[SOLV]Trying to change the value of a drop down list with JS

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

[SOLV]Trying to change the value of a drop down list with JS

Post by impulse() »

I only know the very basic of Javascript so I'm going to have to ask for help on this one. I'm not sure if it's possible as I've been Googling for the past 30 minutes.

I have a drop down list with 2 potential values (Y or N) and they're all defaulted to Y. I'm trying to find some code that will change the value of all the drop down lists to N on the click of a button. I keep getting the error 'el is not defined'

This is the code I have at the moment:

Code: Select all

<script>
    function changeValue() {
      document.test.list.el.selectedIndex = 0;
    }
  </script>
Last edited by impulse() on Fri Jun 29, 2007 8:10 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

document.forms['yourFormName'].elements['yourElementName'].options[yourSelectedIndex].selected = true;
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Thank you.
Post Reply