Re: Beginner form validation
- From: "Dag Sunde" <me@xxxxxxxxxxxx>
- Date: 31 May 2006 23:13:04 +0200
Jessica wrote:
Can someone look at this code and tell me what is wrong? The error
message says "Line 8 Char 1 'dealerId' is undefined" But I thought
that I stated everything correctly. Do I have any syntax errors in
here. The code is supposed to display an alert if someone typed in
letters instead of numbers for each input box.
---------------------------------------------------------------------------------------------------------------------------------------
<script>
function validateInputs() {
var validInputs=(IsValidNumber(dealerId,DealerID)
&&IsValidNumber(seriesId,SeriesID)
&&IsValidNumber(modelId,ModelID)
&&IsValidNumber(extColorId,ExteriorColorID)
&&IsValidNumber(fabricTypeId,FabricTypeID));
if(!validInputs){
return false;
}
}
function IsValidNumber() {
var input = document.getElementById(inputId);
if(!validateNumber(input,inputDescription)){
return false;
}else{
return true;
}
}
var re = /^\d+$/;
function validateNumber(input, inputName) {
var validNumber = re.exec(input.value);
if (!validNumber) {
alert("Input a valid number in " + inputName + " now!");
input.focus();
return false
} else {
return true;
}
}
</script>
html:
<form id="Form1" action="DisplayMultipleProcedures.aspx" method="post"
onsubmit="return validateInputs();">
Thanks :)
You have forgot to declare the parameters in "function IsValidNumber()":
function IsValidNumber(inputId, inputDescription) { ...
Also, the way you use those params, you have to give them as strings
when you call "IsValidNumber(...)", like this:
function validateInputs() {
var validInputs=(IsValidNumber('dealerId', 'DealerID')
&& IsValidNumber('seriesId', 'SeriesID')
&& IsValidNumber('modelId', 'ModelID')
&& IsValidNumber('extColorId', 'ExteriorColorID')
&& IsValidNumber('fabricTypeId', 'FabricTypeID'));
return validInputs;
}
--
Dag.
.
- References:
- Beginner form validation
- From: Jessica
- Beginner form validation
- Prev by Date: No properties
- Previous by thread: Re: Beginner form validation
- Next by thread: No properties
- Index(es):
Relevant Pages
|