PDA

View Full Version : Disabled Submit Button


moracom
07-19-2005, 05:04 PM
I have this javascript that checks that one of the two input fields are filled in. If not the submit button is disabled. The script works well. But now i have two input fields that are required. How do I add the second field in the script.

Here's my code:

<script>
function checkifempty5(){
if (document.DaForm5.Zip.value=='')
document.DaForm5.button5.disabled=true
else
document.DaForm5.button5.disabled=false
}
if (document.all || document.getElementById)
setInterval("checkifempty5()",100)
</script>
<form action="searchresultsZIP.asp" method="post" name="DaForm5">

Zip/PostalCode:&nbsp;&nbsp;<input type="text" size="10" maxlength="10" name="Zip" style="color:#336699; border: 1px solid; border-color: #999999;font: 11px/16px Tahoma, Verdana, sans-serif;">

Phone&nbsp;&nbsp;<input type="text" size="10" maxlength="10" name="Phone" style="color:#336699; border: 1px solid; border-color: #999999;font: 11px/16px Tahoma, Verdana, sans-serif;">

<input type="submit" name="button5" value="Search" style="color:#336699; border: 1px solid; border-color: #999999;font: 11px/16px Tahoma, Verdana, sans-serif;"></form>

Johnny Lang
07-19-2005, 05:12 PM
By way of example:

<HTML>
<Head>
<Script Language=JavaScript>

function checkIt(){

isEmail = document.forms.Form1.emailAddr.value;
isComment = document.forms.Form1.comments.value;
if (isEmail.length >= 4 && isComment.length >= 6)
{document.getElementById('submitBtn').disabled = false}
else {document.getElementById('submitBtn').disabled = true}
}

function init(){

document.getElementById('submitBtn').disabled = true;
}

window.onload=init;

</Script>
</Head>
<Body>

<Form name='Form1'>
Email: <input type=text name='emailAddr' onblur="checkIt()" onclick="this.value='';init()"><br>
Comments: <input type=text name='comments' onblur="checkIt()" onclick="this.value='';init()"><br>
Nothing: <input type=text name='empty'><br><br>
<input type=Submit id='submitBtn'>
</Form>

</Body>
</HTML>

moracom
07-19-2005, 05:20 PM
thanks Johnny!

Johnny Lang
07-19-2005, 05:33 PM
No problem. Take care.