Results 1 to 2 of 2

Thread: Change Value from Select Menu Based on the value of a javascript variable

  1. #1
    Join Date
    Mar 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Change Value from Select Menu Based on the value of a javascript variable

    Hi,

    I am creating a quoting program for our organisation and need the program to select/change the value which is selected by default in the drop down menu, based on whether another variable on the page is Yes or No.

    Is anybody able to help me? This is rather urgent.

    Thanks heaps,
    Caleb

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There are many ways to access a form element and also many ways to determine the value of a variable and then branch your code depending upon what that value is. I'm assuming that you know which one's that you would like to use. Here is one way of changing the selected option of a drop down:

    Code:
    <select id="sel">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    </select>
    <script type="text/javascript">
    document.getElementById('sel').options[3].selected=true
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •