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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selecting a form list item with JS link

    I've got a list/menu item in a search form ...

    <select name="ccode" id=ccode >
    <option value=0>World</option>
    <OPTION VALUE="1" >Afghanistan</OPTION>
    <OPTION VALUE="2" >Albania</OPTION>
    <OPTION VALUE="3" >Algeria</OPTION>
    <OPTION VALUE="4" >American Samoa</OPTION>
    <OPTION VALUE="5" >Andorra</OPTION>
    etc, etc.
    </select>

    Since this list include every country in the world (a long list) I'd like to offer users the a few text links along the side that select popular countries within the list without having to scroll through the huge list ... click here to select United States, click here to select Japan, etc.

    How would I do this with JS? I appreciate any guidance.

    Thanks!

    J.R.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function selectOpt(what)
    {
    document.forms[0].ccode.options[what].selected = true;
    }
    </script>
    </head>
    
    <body>
    <a href="#" onclick="selectOpt(3);return false">Select Algeria</a><br>
    <a href="#" onclick="selectOpt(1);return false">Select Afghanistan</a><br>
    <a href="#" onclick="selectOpt(5);return false">Select Andorra</a><br>
    <form action="#">
    <select name="ccode" id="ccode" >
    <option value="0">World</option>
    <option value="1" >Afghanistan</option>
    <option value="2" >Albania</option>
    <option value="3" >Algeria</option>
    <option value="4" >American Samoa</option>
    <option value="5" >Andorra</option>
    </select>
    </form>
    </body>
    </html>
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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