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

server validation - getting drop downs to reflect value

Status
Not open for further replies.

leeolive

Programmer
May 14, 2002
46
GB
Hi

I got some great server side validation code from here

The form checks if all the fields are completed etc. When user clicks submit and a field is not completed it marks that textbox as "required" and displays the form again. All the other values the user entered correctly are displayed, but the drop downs don't reflect the values. How do I get them to reflect the values. I have tried to do option value = request. querystring etc but this doesn't work. It will be frustrating if the user has completed the entire form minus one text box. They then complete that text box but now they have to re do all the drop downs. Anyone have a solution? Appreciate it. Thanks! Lee

Here's some of the relevant code

<%

Dim bError
Dim bIsSubmitted

bError = false

' IsSubmitted is hidden field in form
If Request.QueryString(&quot;IsSubmitted&quot;) = &quot;&quot; Then
bIsSubmitted = false
Else
bIsSubmitted = true
End If


Function IsSelected(sFieldname, sOption)
IsSelected = &quot;&quot;
For Each sSelection in Request.QueryString(sFieldname)
If Trim(sSelection) = sOption Then
IsSelected = &quot; selected&quot;
End If
Next
End Function
%>

FORM STARTS HERE
<tr>
<td align=&quot;left&quot; width=&quot;430&quot;>Title</td>
<td align=&quot;left&quot; width=&quot;5&quot;> &nbsp; </td>
<td align=&quot;left&quot;>
<select name=&quot;Title&quot; class=&quot;inputpension&quot;>
<option></option>
<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Ms</option>
<option>Dr</option>
<%
aOptions = Array()
For each sOption in aOptions
sSelected = IsSelected(&quot;Title&quot;, sOption) ' Call IsSelected function
Response.Write &quot;<option&quot; & sSelected & &quot;>&quot; & sOption & &quot;</option>&quot;
Next
%>
</select><img src=&quot;images/required_image.gif&quot; width=&quot;10&quot; height=&quot;9&quot; alt=&quot;Expat Financial&quot; />
<%
Response.Write RequiredFieldValidation(&quot;Title&quot;, &quot;required&quot;)
%>
</td>
</tr>
 
Hi,

There are a couple of things wrong here:

firstly, you need to check whether your form method is POST or GET (it's usually post but your code seems to be assuming a GET method) if it using POST then you need to change request.querystring to request.form whenever you use it to access a form variable.

Secondly, none of your select box options actually hav values, all of the options must have a value which is then submitted to the form, you then use this to determine if it was selected.
i.e.
<option value=&quot;MR&quot;>Mr</option>
<option value=&quot;MRS&quot;>Mrs</option>

This should then work...

Thanks



Hope this helps,

Phil Clare
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top