
December 6th, 2007, 02:13 AM
|
|
Contributing User
|
|
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 65
Time spent in forums: 1 Day 1 h 5 m 28 sec
Reputation Power: 4
|
|
|
Need Help Debugging Script/Error in Script - Need help with form validation and disable submit button
Hey there
I have a form in which I need the submit button disabled and for the form to be validated before submitting the data.. I've tried different ways but I can't seem to get it working properly.. The closest I've gotten it to work is the following code:
Code:
<script language='javascript'>
function ValidateForm(form)
{
function IsNumeric(sText)
{
var ValidChars = "0123456789";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
if (!IsNumeric(form.price.value))
{
alert('Please enter only numbers in the price fields')
form.price.focus();
return false;
}
if (!IsNumeric(form.price_g.value))
{
alert('Please enter only numbers in the price fields')
form.price_g.focus();
return false;
}
return disableButton(document.form)
}
function disableButton(theButton) {
theButton.value="Uploading...";
theButton.disabled = true;
return true;
}
</script>
However, it's not submitting my data (am trying to upload files to my server)..
Here's my form tags:
Code:
<form action="uploader.php" method="post" enctype="multipart/form-data" name="form" id="form" onSubmit="javascript:return ValidateForm(this)">
.....
<input name="upload" type="submit" id="upload" value="Submit" />
Could someone please let me know what I'm doing wrong??
Thanks so much 
|