SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,211
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    going to pg1.html directly when it's selected

    Code:
    <script type='text/javascript'>
    window.onload = function()
    {
      document.getElementById('menu1').onchange = ddmOnChange;
    }
    function ddmOnChange()
    {
      var url = this.options[this.selectedIndex].value;
      document.location = url;
    }
    </script>
    
    <select id='menu1'>
    <option value='pg1.html'>Page 1</option>
    <option value='pg2.html'>Page 2</option>
    </select>
    With the code above if a user selects one of option, it will go to the page selected.


    I like to put two selects in a page like the below.

    The following trial code doesn't work correctly, but it will show what I want.

    Code:
    trial code
    
    <script type='text/javascript'>
    window.onload = function()
    {
      document.getElementById('menu1').onchange = ddmOnChange;
    }
    function ddmOnChange()
    {
      var url = this.options[this.selectedIndex].value;
      document.location = url;
    }
    </script>
    
    <select id='menu1'>
    <option value='pg1.html'>Page 1</option>
    <option value='pg2.html'>Page 2</option>
    </select>
    
    <script type='text/javascript'>
    window.onload = function()
    {
      document.getElementById('menu2').onchange = ddmOnChange;
    }
    function ddmOnChange()
    {
      var url = this.options[this.selectedIndex].value;
      document.location = url;
    }
    </script>
    
    <select id='menu2'>
    <option value='pg3.html'>Page 3</option>
    <option value='pg4.html'>Page 4</option>
    </select>
    How can I make the trial code above work fine?

    (With the trial code above, option "Page 3" and option "Page 4" work fone.
    But, option "Page 1" and option "Page 2" don't work correctly.)
    Last edited by dotJoon; Dec 5, 2006 at 07:11.

  2. #2
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've assigned window.onload two different events - but only one will take. Try re-writing your window.onload:
    PHP Code:
    window.onload = function() {
      
    document.getElementById('menu1').onchange ddmOnChange;
      
    document.getElementById('menu2').onchange ddmOnChange;
    }; 
    HTH,

    Jon


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
  •