I want to disable submit button using javascript if textbox is blank and enable it when someone fills textbox. Is it possible to do it in javascript?
following example would be helpful.. <html> <head> <script language="javascript"> function disab() { frm=document.forms[0]; if(frm.tbox.value.length <= 0) { frm.button1.disabled=true; } else { frm.button1.disabled=false; } } </script> </head> <body text="000000" bgcolor="ffffff"> <form> <input name="tbox" type="text" id="tbox" value="" onkeyup=disab();> <input type="button" onclick="alert('button pressed!')" value="button" name="button1" disabled="false"> </form> </body> </html> HTML:
Does it matter? I ask because someone suggested I use that in a character-counting script where people filled in a text area and could see how many chars they've typed... they suggested it because they said, "what if people copy and paste instead of type?" but I tested it and it didn't matter... ctrl+v was also a keyup event. But I would like to hear more reasons why, as I do keep hearing that suggestion. I thought onchange was more for selects?