?
Solved

select detect impossible?

Posted on 1998-02-02
2
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 80 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

764 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