2

I have a select option :

<select>
    <option value="select">select</option>
    <option value="audi">Audi</option>
    <option value="bmw">BMW</option>
    <option value="vw">VW</option>
</select>

Now what I want is that whatever option I select from the dropdown, the value in the select should always be "select". Thanks.

2
  • 1
    set the value attribute of al the <option>'s to select? Commented Oct 17, 2012 at 7:59
  • 2
    You should explain what you really mean and why. Phrases like “the value in the select” are vague and ambiguous. And it really sounds like you would want to create a select element where all choices have the same effect – why? Commented Oct 17, 2012 at 8:15

3 Answers 3

3

you could try something like this:

<select id="yourselect">
    <option value="select">select</option>
    <option value="audi">Audi</option>
    <option value="bmw">BMW</option>
    <option value="vw">VW</option>
</select>


<script>
   var s = document.getElementById('yourselect');
   s.onchange = function() {
      s.selectedIndex = 0;  // on change event always select the first option
   }
</script>

Example Fiddle : http://jsfiddle.net/8geek/

Sign up to request clarification or add additional context in comments.

1 Comment

document.getElementById('youselect'); should be document.getElementById('yourselect');
0

Add an event listener for an onchange event, in that listener you set the currently selected option to Select dynamically

Comments

0

Like Jukka mentioned, it seems like you want a select element where all the choices have the same effect? However, you should at least store the the chosen option.

Maybe this is something you are looking for: http://jsfiddle.net/NfRRM/

1 Comment

The effect should not be the same. I am calling different functions on selection of different options. Only what option I have selected should not be reflected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.