Solved

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

Posted on 2011-02-16
2
327 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now