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
    Regular Coder
    Join Date
    Nov 2003
    Location
    Bloomsbury, London
    Posts
    102
    Thanks
    3
    Thanked 0 Times in 0 Posts

    What does this Javascript do please?

    I have this script in the header of numerous pages of my site. The site was constructed a few years ago and now I can't remember what it does:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function formHandler(form){
    var URL = document.form.site.options[document.form.site.selectedIndex].value;
    window.location.href = URL;
    }
    // End -->
    </SCRIPT>
    Anyone have an idea? Cheers
    Domain Exhibit - premium domain names and websites with significant traffic | quote Coding Forums for additional 15% discount!
    Coding Freebies - free scripts and software worth hundreds of dollars

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Go to web page selected from a SELECT element

    Hi,

    This script looks like it is designed to select a web page from a drop down box and redirect the user to this page.

    say you had this form on your page:

    <FORM NAME="URLform">
    <SELECT>
    <OPTION>http://www.somewhere.com/url1.html"</OPTION>
    <OPTION>http://www.somewhere.com/url2.html"</OPTION>
    <OPTION>http://www.somewhere.com/url3.html"</OPTION>
    </SELECT>
    </FORM>

    You would call the script using something like this:

    <INPUT TYPE="button" VALUE="Go To URL" ONCLICK="formHandler(URLform);">

    When the user clicks on the button they will be directed to the selected option, which will open in the current window (window.location.href = ...)

    Mark

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Without seeing the markup that it is meant to go with, it is a little hard to tell. It probably was meant to do something like what this does:
    Code:
    <html>
    <head>
    <title>Drop Nav - Demo</title>
    <script type="text/javascript">
    function formHandler(form){
    var URL = document.forms[form]['site'].options[document.forms[form]['site'].selectedIndex].value;
    window.location.href = URL;
    }
    </script>
    </head>
    <body>
    <form name="nav">
    <select name="site">
    <option value="http://www.yahoo.com">Yahoo
    <option value="http://www.google.com">Google
    <option value="http://www.codingforums.com">Coding Forums
    </select>
    <input type="button" value="Go" onclick="formHandler('nav')">
    </form>
    </body>
    </html>


  •  

    Posting Permissions

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