Helping ordinary people create extraordinary websites!
   

How can I disable my submit button if the textarea in my form is empty?

Thursday, 17th September 2009
by Texas


I want to somewhat prevent users from submitting a form if they have not entered any text in the textarea by disabling the submit button using JavaScript.





tiru_pelli
<html>
<head>
<script type="text/javascript">
function disable()
{
if(document.textArea.text.value=="")
{
document.textArea.submit.disabled=true;
}
else
{
document.textArea.submit.disabled=false;
}
}
</script>
</head>
<body onload="javascript:disable();">
<form name="textArea">
<textarea name="text" rows="2" cols="10" onkeypress="javascript:disable();"></textarea>
<input type="submit" name="submit">
</form>
</body>
</html>
Friday, 18th September 2009
Votes:
40
17

More JavaScript Help:
» How can I automatically submit a form using JavaScript?
» Write a javascript code that verifies all textboxes has been filled.
» How to create a Facebook like popop that shows an animation then the content?
» How to send post data to the server without loading a new page?
» How to enable and check if JavaScript enabled?
» How to use Javascript to produce a dynamic population clock?
» Moving the content of a div to another div
» How can I create Facebook applications?