[thelist] Form validation using ASP

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Mon Mar 12 14:12:26 CDT 2007


Hi Kevin,

    I believe your basic problem here is a misunderstanding of how the HTML form elements work.  The input type="text" element is the only one whose display value can be altered by the value attribute.  The others work as follows:

checkbox:  the "checked" attribute must be present in the element to be checked.

radio button:  same way.

dropdownlist:  the "selected" attribute must be present in any and all items to be selected.

textarea:  the content must be placed between the opening and closing tags of the textarea.

    Does that help?

Peter

----------------------------------------

From: Kevin Stevens kjs at ratking.co.uk

I have a simple booking form with text boxes, check boxes, text areas, 
and dropdown boxes. I am trying to validate this information using ASP, 
sending it to another page to do this, then redirecting back to the 
first one if there is something missing in the required fields. The 
trouble is, the text boxes retain their information, but the check boxes 
are un-ticked, the text areas are blank, and the dropdowns go back to 
their original Select setting. I have been scouring the Internet and 
found some useful code but I can't get any of it to work. Here is an 
example of what I've been trying 
http://www.ratking.co.uk/manhire/test.asp , the code is below...

<%
if Session("Errors")=0 then
response.write "Fields marked * are 
required."
else
'ERRORS WERE MADE SO LIST THEM IN THE REST OF THE TABLE
'reset our error counter
Session("Errors")="0"
response.write "
There are errors in your data. " & _
"Please make the following changes before " & _
"clicking the submit button:
"
response.write"

"
If Session("badname") = "T" then
Response.write "

The Name 
field must be completed."
Response.write "	 
"
Session("badname")="F"
End If
If Session("badnumber") = "T" then
Response.write "

The Number of 
labourers needed field must be completed."
Response.write "	 
"
Session("badnumber")="F"
End If 
end if
%>

*   	 Number of 
labourers needed:*   	 Select 1 2 3
	 Tick if 
necessary:   	 ">High visible vest

">Hard hat

">Steel toe-cap boots

If you need the code to the other page I'll post that as well.

Thanks

-- 
Kevin Stevens
kjs at ratking.co.uk



More information about the thelist mailing list