Re: Beginner form validation



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.


.



Relevant Pages

  • Beginner form validation
    ... Do I have any syntax errors in here. ... var validInputs= ... var input = document.getElementById; ... var validNumber = re.exec; ...
    (comp.lang.javascript)
  • Re: show where image map is clicked?
    ... var D = document.createElement; ... function mark1(what, num) { ... var input = document.getElementById.value; ...
    (comp.lang.javascript)