Solved

select detect impossible?

Posted on 1998-02-02
2
167 Views
Last Modified: 2008-03-06
I have a select box (drop down list) on my html form. Is it possible to detect which one of the options is currently selected BEFORE the user presses the submit button using javascript??
e.g. The select box contains the following, choice1,choice2,choice3,choice4. each of the choices has a value associated with it:£5,£10,£15,£20. I also have a text box which I want to populate with the value according to which choice from the select box is currently selected. so, if the choose choice1, the text box is updated to display £5. I was thinking of catching the ONBLUR or ONCHANGE event of the select box to call a javascript function which populates the text box with: selectbox.option.selected, or even looping through each of the options to see which one had its selected property set, but it doesn't work. Is there any way to do this? (using ie.3 and netscape 3)
cheers for any suggestions.
0
Comment
Question by:acsmith
2 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 20 total points
ID: 1277946
I guess the problem is in your "selectbox.option.selected" which just checks for an option named "option" to be selected.

Here is a sample:

--//--
<HTML>
  <HEAD>
    <SCRIPT LANGUAGE="JavaScript1.1"><!--
      function selectChange(aSelect, aText) {
        aText.value = aSelect.options[aSelect.selectedIndex].text;
        return true;
      }
    // --></SCRIPT>
  </HEAD>
  <BODY>
    <FORM NAME="theForm">
      <INPUT TYPE="text" NAME="theText" VALUE="£5">
      <SELECT NAME="theSelect" onChange="JavaScript:selectChange(theSelect, theText);">
        <OPTION VALUE="0" SELECTED>£5
        <OPTION VALUE="1">$10
        <OPTION VALUE="2">&15
        <OPTION VALUE="3">&20
      </SELECT>
    </FORM>
  </BODY>
</HTML>
--//--

HTH, julio
0
 
LVL 1

Author Comment

by:acsmith
ID: 1277947
thankyou!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

757 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