Varied multiple fields, one submit button. What went wrong?
Posted: Tue Jan 25, 2011 2:54 pm
Greetings, fellow developers. A noob here again, and I've been struggling with this chunk of code for quite a while. I want to ensure three things occur before the submit button is not grayed out:
1. A country is selected and not the empty ----- line.
2. A string more than 2 characters long is input in the zip field.
3. A checkbox must be checked.
Once all three of those conditions are met, the button should be un-grayed and thus go to the next page, with $_POST values for the form fields. Will that be automatic or should I add $_POST somewhere in it?
Here is my code, I am sure I am missing some minor detail that is the cause of the whole mess.
1. A country is selected and not the empty ----- line.
2. A string more than 2 characters long is input in the zip field.
3. A checkbox must be checked.
Once all three of those conditions are met, the button should be un-grayed and thus go to the next page, with $_POST values for the form fields. Will that be automatic or should I add $_POST somewhere in it?
Here is my code, I am sure I am missing some minor detail that is the cause of the whole mess.
Code: Select all
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">
<!--
function toggleButton()
{
if ((document.getElementById("country").elements[0].value != "") && (document.getElementById("zipcodetitle").elements[1].value.length > 2) && (document.getElementById("chk1").checked == true))
{
document.frm1.orderbutton.disabled = false;
}
else
{
document.getElementById("orderbutton").disabled = true;
}
}
-->
</script>
</head>
<body>
<form name="frm1" id="frm1">
<p>Country: <select tabindex="70" name="country" id="country" onMousedown="javascript:toggleButton();">
<option value="US" selected="selected">United States
<option value="CA">Canada
<option value="">————</option>
<option value="AX">Aland Islands</select></p>
<p>Zip Code/Postal Code: <input name="zipcodetitle" type="text" id="zipcodetitle" size="12" class="formfont" onkeydown="javascript:toggleButton();"> </p>
<input type="checkbox" id="chk1" name="chk1" onchange="javascript:toggleButton();" value="1" /><p>
<input type="submit" width="700" value="Continue" name="orderbutton" id="orderbutton" class="formfont"
disabled="disabled">
</p>
</form>
</body>
</html>