Solved

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

Posted on 2011-02-16
2
326 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
Comment Utility

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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

743 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

13 Experts available now in Live!

Get 1:1 Help Now