Submit via javascript

Fermé
cs78 Messages postés 1 Date d'inscription mardi 25 juin 2013 Statut Membre Dernière intervention 25 juin 2013 - 25 juin 2013 à 18:32
SlyK Messages postés 854 Date d'inscription vendredi 11 mars 2011 Statut Contributeur sécurité Dernière intervention 6 octobre 2014 - 25 juin 2013 à 19:46
Bonjour,

Pouvez-vous me dire pourquoi ce code ne fonctionne pas.
dès que je mets un "IF" dans la fonction test, le submit ne marche plus.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Document sans nom</title>
<script language="javascript"> 
function test() 
{
var Stypes = (document.forms["form1"].select.value);
alert (Stypes);
	
if document.forms["form1"].select.value =="2" {document.forms['form1'].submit(); }
}
</script>
</head>

<body>
<form action="test1.html" method="post" name="form1" target="_blank" id="form1">
  <label for="select"></label>
  <p>
    <select name="select" id="select">
      <option value="1">Choix11</option>
      <option value="2">Choix2</option>
      <option value="3">Choix3</option>
    </select>
</p>
<p>
    <input type="button" onclick="javascript:test()" name="pp" value="Bouton" id="pp"  />
</p>
</form>
</body>
</html>


Merci d'avance pour votre aide
Christophe

A voir également:

1 réponse

SlyK Messages postés 854 Date d'inscription vendredi 11 mars 2011 Statut Contributeur sécurité Dernière intervention 6 octobre 2014 147
25 juin 2013 à 19:46
Hello,

Tu as oublié de mettre ta condition entre parenthèse.

if (document.forms["form1"].select.value == "2") {
    document.forms['form1'].submit(); }
}



Cordialement.
0