Solved

Classic ASP - Function to check that the user has selected a value

Posted on 2011-02-16
2
328 Views
Last Modified: 2012-05-11
I am trying to update one of my asp pages so that it forces the user to select a value in a drop down list box. Currently it defaults to one of the values but users then never change it, I would like to force them to choose one.

What is the easiest simplest way to do this?


<td align="right" nowrap>when would you like us to call you?&nbsp;&nbsp;</td>
                  <td align="left"> <select class="inputfield" name="TimeRequired">
                      <!--<option value="0" <%if Cstr(callerRequestTime) = "0" then response.write("selected")%>>Immediately!</option>-->
			<option value="15" <%if Cstr(callerRequestTime) = "15" then response.write("selected")%>>in 
                      15 minutes</option>
                      <option value="30" <%if Cstr(callerRequestTime) = "30" then response.write("selected")%>>in 
                      30 minutes</option>
                      <option value="60" <%if Cstr(callerRequestTime) = "60" then response.write("selected")%>>in 
                      one hour</option>
                    </select> </td>

Open in new window

0
Comment
Question by:Lico_w
2 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 250 total points
ID: 34905028

Are you after something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26824839.html</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

jQuery(document).ready( function () {

  var original = $("#TimeRequired>option:selected").val();

  $("#postback").click( function() {
    $("#error").empty();
    if ( original == $("#TimeRequired>option:selected").val() ) {
      $("#error").text( "Error: please select another time." ).css( { color: "#f00" } );
    }
  });

});

</script>
</head>
<body>

<select id="TimeRequired">
  <option value="0">Immediately!</option>
  <option value="15">in 15 minutes</option>
  <option value="30" selected="true">in 30 minutes</option>
  <option value="60">in one hour</option>
</select>

<input id="postback" type="button" value="Postback">

<span id="error"></span>

</body>
</html>

Open in new window

0
 
LVL 10

Assisted Solution

by:John Claes
John Claes earned 250 total points
ID: 34905044
add a option "[Select]" with value -10
Make this the first and default value of the dropdown.

This ensures that the user sees that he must change the dropdown. and you can check if he did ;-)

regards

poor beggar
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question