deadlydragon121
09-20-2011, 12:14 PM
Hi, I am having a problem with my script used to disable my submit button. I want the button to disable upon correct submission of the form, and the button to be kept enabled if the required fields are not filled in. I have the following code at the moment (which only does the first if statement).
SCRIPT CODE:
<script type="text/javascript" >
function validateForm()
{
var amount=document.forms["expenserecord"]["amount"].value;
var picker=document.forms["expenserecord"]["picker"].value;
var desc=document.forms["expenserecord"]["description"].value;
if (amount==null || amount=="" || picker==null || picker=="" || desc==null || desc=="") {
alert("All required fields must be filled out.");
document.getElementById("sub").disabled = false;
return false;
}
else {
document.getElementByID("sub").disabled = true;
}
}
</script>
BUTTON CODE:
<p><input type="submit" value="Submit" onClick="return validateForm()" id="sub"></p>
SCRIPT CODE:
<script type="text/javascript" >
function validateForm()
{
var amount=document.forms["expenserecord"]["amount"].value;
var picker=document.forms["expenserecord"]["picker"].value;
var desc=document.forms["expenserecord"]["description"].value;
if (amount==null || amount=="" || picker==null || picker=="" || desc==null || desc=="") {
alert("All required fields must be filled out.");
document.getElementById("sub").disabled = false;
return false;
}
else {
document.getElementByID("sub").disabled = true;
}
}
</script>
BUTTON CODE:
<p><input type="submit" value="Submit" onClick="return validateForm()" id="sub"></p>