<form name="formular" action="cualquiera.html" method="post">
<select name="transporte" type="check"onclick="document.formular.enviar.disabled=!document.formular.enviar.disabled" >
<option >Coche</option>
<option >Avión</option>
<option >Tren</option>
</select>
<input type="submit" name="enviar" value="Enviar" disabled>
</form>
I have used the event
Onchange
instead ofonClick
and checking if the selected index is different from the first one so that if there is none selected, it will block again.The change you made from the negation of the previous state made it intermittently lock and unlock the button without any useful logic.
Following your development style a bit, here I show you how you should do it:
However, it is important to mention that although you can do it, it is not good practice to place the javascript code inside the event
onClick
onChange
, etc., the correct thing is to create a function with the javascript code and that it be called when the event occurs, in the following example I show you a good practice of how to do: