Form Validation

Compare/validate form input element with contents of another form elem

Page 1 of 1

1 Replies - 1605 Views - Last Post: 02 March 2009 - 04:59 PM Rate Topic: -----

#1 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 191
  • Joined: 03-December 08

Form Validation

Post icon  Posted 02 March 2009 - 11:58 AM

In the html/asp code that follows I have a select tag (html drop down menu) that is populated via a database query. This allows the end user to select from the list to run a report. Also in the form is a text input field for the end user to type directly the report name that they want, thus saving them the hassle of scrolling through the drop menu.

What I would like to do is take whatever the user types into the text field and compare it against the contents of the drop menu.

Sort of like, IF the value of the text input field = one of the drop menu items THEN do something. I could probably just take the user input and run another database query against the input, but I would really like to try it this way.

Basically what I am going for here is to validate the user input against the list to make sure what they have typed in is actually in the record set (the database) I figured a good way to do this was to compare it to what is in the drop menu list since that is the contents of the database. If not, it will alert them that the record does not exist.

Not sure where to start with this. My code follows. Any suggestions will be greatly appreciated. Thank you!

<form action="" name="rpt_form" method="POST">
		<input type="hidden" name="posty" value="1"/>
		<table width="98%" border="0" bordercolor="#0000ff" cellpadding="0" cellspacing="0" class="dinq_table">
			<tr>
				<div class="header">
					Choose options:
				</div>
				<td valign="top" align="left">
					<div class="options">
						<p><span class="bold">Select one or multiple Vulnerabilities:<br>
						<span class="bold_italic_tiny">(Use ctrl or shift for multiple selections):</span></span><br>
						  <SELECT onfocus="document.rpt_form.search_vuln.value='';" NAME="selected" class="text_tiny" SIZE="8" multiple>
															  <%
									While Not rs.EOF 'Don't show vuln if not passed cutoff time (1600 gmt)
										if((today > cdate(rs("duedate"))) OR _
											(today = cdate(rs("duedate")) AND passed_compliant_time = 1)) then%>
							<option value="<%=rs("ID")%>"><%=rs("AlertNum")%></option>
								<%
										end if
									rs.movenext
									Wend%>
						  </SELECT>
						  <p><span style='color: red'>--OR--</span>
					  
						  <p>
						  
						  <span class="bold">Search for a single specific Report:</span><br>
						  <span class="bold_italic_tiny">Format must match examples above</span><br>
						  
							<INPUT onfocus="document.rpt_form.selected.value='';" onkeyup="upperCase(this.id)" type="text" name="search_vuln" value="" size="30" id="search"><br>
							  <%if request.Form <> "" AND request.Form("search_vuln") = "" AND request.Form("selected") = "" then%>
						  <span class="error">You must select the report you want.</span>
							  <%end if%>
						 
					  <p>
								  <span class="bold_italic_tiny">Select Type List Report:</span><br>
								  <span class="text_tiny">
									  <input type="radio" name="dinq_rpt_type" value="1">
									<a href="#" onmouseover="ddrivetip('DINQ List displays all commands who are delinquent at the time of the IAVA(s) comply by date.  If the command has updated their status after the comply by date it will not be reflected in this list.');" onmouseout="hideddrivetip();">DINQ List</a><br>
									  <input type="radio" name="dinq_rpt_type" value="2">
									<a href="#" onmouseover="ddrivetip('Disconnect List displays all commands who are not in compliance with the IAVA(s) at the time the list is generated.');" onmouseout="hideddrivetip();">Disconnect List</a><br>
						  </span>
							<%if request.Form <> "" AND request.Form("dinq_rpt_type") = "" then%>
							  <span class="error">You must select the type of report you want.</span>
							<%end if%>
					<p>
						  <input type="submit" class="btn" value="Get Report" id="submit_dinq" onmouseover="set_class_name(this,'btn btnhov');" onmouseout="set_class_name(this,'btn');">
						  <br>
						  <br>
					</div>
			</td></tr>
		</table>
	</form>



Is This A Good Question/Topic? 0
  • +

Replies To: Form Validation

#2 doWhileSomething  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 96
  • Joined: 08-January 09

Re: Form Validation

Posted 02 March 2009 - 04:59 PM

View Postmidasxl, on 2 Mar, 2009 - 10:58 AM, said:

In the html/asp code that follows I have a select tag (html drop down menu) that is populated via a database query. This allows the end user to select from the list to run a report. Also in the form is a text input field for the end user to type directly the report name that they want, thus saving them the hassle of scrolling through the drop menu.

What I would like to do is take whatever the user types into the text field and compare it against the contents of the drop menu.

Sort of like, IF the value of the text input field = one of the drop menu items THEN do something. I could probably just take the user input and run another database query against the input, but I would really like to try it this way.

Basically what I am going for here is to validate the user input against the list to make sure what they have typed in is actually in the record set (the database) I figured a good way to do this was to compare it to what is in the drop menu list since that is the contents of the database. If not, it will alert them that the record does not exist.

Not sure where to start with this. My code follows. Any suggestions will be greatly appreciated. Thank you!

<form action="" name="rpt_form" method="POST">
		<input type="hidden" name="posty" value="1"/>
		<table width="98%" border="0" bordercolor="#0000ff" cellpadding="0" cellspacing="0" class="dinq_table">
			<tr>
				<div class="header">
					Choose options:
				</div>
				<td valign="top" align="left">
					<div class="options">
						<p><span class="bold">Select one or multiple Vulnerabilities:<br>
						<span class="bold_italic_tiny">(Use ctrl or shift for multiple selections):</span></span><br>
						  <SELECT onfocus="document.rpt_form.search_vuln.value='';" NAME="selected" class="text_tiny" SIZE="8" multiple>
															  <%
									While Not rs.EOF 'Don't show vuln if not passed cutoff time (1600 gmt)
										if((today > cdate(rs("duedate"))) OR _
											(today = cdate(rs("duedate")) AND passed_compliant_time = 1)) then%>
							<option value="<%=rs("ID")%>"><%=rs("AlertNum")%></option>
								<%
										end if
									rs.movenext
									Wend%>
						  </SELECT>
						  <p><span style='color: red'>--OR--</span>
					  
						  <p>
						  
						  <span class="bold">Search for a single specific Report:</span><br>
						  <span class="bold_italic_tiny">Format must match examples above</span><br>
						  
							<INPUT onfocus="document.rpt_form.selected.value='';" onkeyup="upperCase(this.id)" type="text" name="search_vuln" value="" size="30" id="search"><br>
							  <%if request.Form <> "" AND request.Form("search_vuln") = "" AND request.Form("selected") = "" then%>
						  <span class="error">You must select the report you want.</span>
							  <%end if%>
						 
					  <p>
								  <span class="bold_italic_tiny">Select Type List Report:</span><br>
								  <span class="text_tiny">
									  <input type="radio" name="dinq_rpt_type" value="1">
									<a href="#" onmouseover="ddrivetip('DINQ List displays all commands who are delinquent at the time of the IAVA(s) comply by date.  If the command has updated their status after the comply by date it will not be reflected in this list.');" onmouseout="hideddrivetip();">DINQ List</a><br>
									  <input type="radio" name="dinq_rpt_type" value="2">
									<a href="#" onmouseover="ddrivetip('Disconnect List displays all commands who are not in compliance with the IAVA(s) at the time the list is generated.');" onmouseout="hideddrivetip();">Disconnect List</a><br>
						  </span>
							<%if request.Form <> "" AND request.Form("dinq_rpt_type") = "" then%>
							  <span class="error">You must select the type of report you want.</span>
							<%end if%>
					<p>
						  <input type="submit" class="btn" value="Get Report" id="submit_dinq" onmouseover="set_class_name(this,'btn btnhov');" onmouseout="set_class_name(this,'btn');">
						  <br>
						  <br>
					</div>
			</td></tr>
		</table>
	</form>



You could build a javascript method that takes each char from the input box and does a comparison against each item in the drop down list, possibly waiting until there is at least 2-3 chars in the text box before doing any evaluation.

<input type="text" onkeyup="matchInputAgainstDropDown(this);" />

Then, loop through each item in the drop down, and see if any item starts with/matches that of the input box. If so, select it.
You may also want to make both items (input and drop down) text lower case to make it easier to match. Some people won't type in proper case when doing a search.

My 2 cents.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1