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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Validating Form 1

Status
Not open for further replies.

JohnBoy2005

Programmer
Jul 12, 2005
117
GB
I'm trying to validate a form to make sure all the input boxes have entries in them before I submit to the next page.

The problem I have is that the names of the input boxes can change depending on the results of the page.

E.G.

Report 1

<input name="Room_1" type="text">
<input name="Room_3" type="text">
<input name="Room_5" type="text">

Or Report 2

<input name="Room_2" type="text">
<input name="Room_4" type="text">
<input name="Room_8" type="text">

Any ideas on how I can validate these input boxes.

Cheers

John
 
Suppose the form name is "x". The function is a fragment of the onsubmit handling.
[tt]
<form name="x" onsubmit="validate" language="vbscript">
[/tt]
The part involving validing all text inputs is like this independent of element's name.
[tt]
function validate
dim bvalid, celem
bvalid=true
set celem=document.x.elements
for i=0 to celem.length
if celem(i).type="text" then
if trim(celem(i).value)="" then
'just for illustration
msgbox celem(i).tagName & vbcrlf & celem(i).name & vbcrlf & "value is empty"
bvalue=false
exit for
end if
end if
next
if not bvalid then window.event.returnvalue=false
end function
[/tt]
This is deliberately scripted in vbscript. If you want javascript, why ask vbscript forum?
 
Correction
The corresponding line should be read like this as a matter of course.
[tt] for i=0 to celem.length[red]-1[/red][/tt]
 
Thanks! and just to note my another obvious typos.
>[self] bvalue=false
[tt]bvalid=false[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top