SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting values in a select box through javascript

    Hi,
    I've searched everywhere for this but can't find it. How can I select a particular value in a select dropdown box using javascript? (I.E a select box has 5 values, how can I select the 3rd?)

  2. #2
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can check whatever is currently selected.

    Code:
    <select name="myList" onchange="alert(this.value);">
                	<option value="1">First</option>
                	<option value="2">Second</option>
                	<option value="3">Third</option>
                </select>
    or you can seperate the code into a function

    Code:
    <script>
    function checkSelected(form) {
    alert(form);
    }
    </script>
    
    <select name="myList" onchange="checkSelected(this.value);">
                	<option value="1">First</option>
                	<option value="2">Second</option>
                	<option value="3">Third</option>
                </select>
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site


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
  •