Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate multiple fields

Status
Not open for further replies.

seaport

MIS
Jan 5, 2000
923
US
I just learned to write Javascript. the following is some code used to validate 9 fields in a form. However, the code does not work. I think the problem is where I try to refer to all textboxes in the form - theform.elements["txtex" + i]. What should I do?

****
function DataValidation(theForm)
{
var i
// alert("All expense field must be entered.");
for (i=1; i<10; i=i+1)
{
if (theform.elements[&quot;txtex&quot; + i]==&quot;&quot;)
{
alert(&quot;All expense field must be entered.&quot;);
return (false);
}
}
return (true);
}

****
I tried to call this function from the following code.

****
<FORM METHOD=&quot;Post&quot; ACTION=&quot;view.ASP&quot; name=&quot;frmBudget&quot; onsubmit=&quot;return DataValidation(this)&quot;>
****


Thanks in advance.

Seaport
 
In your for loop, the line contain
if (theform.elements[&quot;txtex&quot; + i] ==&quot;&quot;)

should put a checking statement, it can replace by

if (theform.elements.type == &quot;text&quot;){
if (theform.elements.value ==&quot;&quot;){
...
}
}




------------------
Freedom is a Right
 
I already know all these txtex1, txtex2, ..., txtex9 are text.

Maybe I need to rephrase my question. Can I retrieve the value of a text in a form like:

theform.elements[&quot;txtex1&quot;].value

Seaport
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top