PDA

View Full Version : Making the submit button disabled till all forms are filled out


jon.php
07-26-2005, 06:32 PM
Well until two text forms are filled out I need the submit button to be disabled. Once there is text in the forms the submit button can be able to be pressed, any idea?

Brandoe85
07-26-2005, 09:47 PM
Basic example...

<html>
<head>
<script type="text/javascript">
function check(frm)
{
var fld1 = frm.fld1.value;
var fld2 = frm.fld2.value;
var sub = document.getElementById('sub');

fld1 != '' && fld2 != '' ? sub.disabled = false : sub.disabled = true
}

</script>
</head>
<body>
<form name="">
<input type="text" name="fld1" onblur="check(this.form);"><br>
<input type="text" name="fld2" onblur="check(this.form);"><br>
<input type="text" name="fld3"><br>
<input type="submit" id="sub" disabled>
</form>
</body>
</html>

glenngv
07-27-2005, 06:28 AM
I prefer that the submit button is disabled programmatically so that the form is still useable even if javascript is disabled.