Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Selecting a select box by clicking a link

    Can someone help me use javascript to select an option from a select box by clicking a link?

    Code:
    <a href="#">option 1</a><br>
    <a href="#">option 2</a><br>
    <a href="#">option 3</a><br><br>
    
    <SELECT  name="form">
      <OPTION value="" selected>Please select a subject</OPTION>
      <OPTION value="">--------</OPTION>
      <OPTION value=optone>Option One</OPTION>
      <OPTION value=opttwo>Option Two</OPTION>
      <OPTION value=optthree>Option Three</OPTION>
    </SELECT>
    So if you click the option three link, the select box will change. Thanks!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    function selectOption(option){
      document.frm.subject.value = option;
      return false;
    }
    Code:
    <form name="frm">
    <a href="#" onclick="return selectOption('optone');">option 1</a><br>
    <a href="#" onclick="return selectOption('opttwo');">option 2</a><br>
    <a href="#" onclick="return selectOption('optthree');">option 3</a><br><br>
    
    <SELECT  name="subject">
      <OPTION value="" selected>Please select a subject</OPTION>
      <OPTION value="">--------</OPTION>
      <OPTION value="optone">Option One</OPTION>
      <OPTION value="opttwo">Option Two</OPTION>
      <OPTION value="optthree">Option Three</OPTION>
    </SELECT>
    </form>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you very much Glenn. This is perfect!


  •  

    Posting Permissions

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