I want to disable an input on submit but it didn't work. I have a select and I want that if it has a certain value it won't be passed in parameter (here the value is "autres") and if this value is selected an input appear and user can type what they want. Here is what I have :
<select name="motif" id="motif" onChange="choix()">
<option value="">-</option>
<option value="formation">Formation</option>
<option value="autres">Autres</option>
</select>
<div id="commentaire"></div>
<input type="submit" value="Envoyer ma demande" id="submit" onClick="disableMotif()"/>
Javascript
function choix()
{
var i = document.getElementById("motif").value;
var comment = document.getElementById("comment");
if (i=='autres' && !comment)
{
$( "#commentaire" ).append( "<div id=\"comment\"> Indiquez le motif : <input type=\"text\" style=\"margin-top:5px;\" name=\"motif\" value=\"\"/></div>" );
}
else{
comment.parentNode.removeChild(comment);
}
}
function disableMotif()
{
var i = document.getElementById("motif").value;
var comment = document.getElementById("comment");
if (i=='autres' && !comment)
{
$("#motif").prop('disabled', true);
}
}
The function for disable the input on submit doesn't work. I have in the parameters 2 times "motif". How can I do this ?