Help this javascript

Discussion in 'HTML' started by ken, Feb 25, 2006.

  1. ken

    ken Guest

    I have the follow javascript.
    Is there anyway of making it more cosmetically more appealing?


    <SCRIPT LANGUAGE="JavaScript">


    function formHandler(form){
    var URL =document.form.site.options[document.form.site.selectedIndex].value;
    window.location.href = URL;}
    </script>

    <form name="form">
    <select name="site" size=1 onChange="javascript:formHandler2()">
    <option value="">Enrollment, Fees, Policies
    <option value="enrollment.html">Enrollment
    <option value="ssh_policies.html">School Policies & Fees
    <option value="schedule.html">Group Class Schedule
    </select>

    Thank

    Ken
     
    ken, Feb 25, 2006
    #1
    1. Advertising

  2. ken

    Jimmy Guest

    ken wrote:
    > I have the follow javascript.
    > Is there anyway of making it more cosmetically more appealing?
    >
    >
    > <SCRIPT LANGUAGE="JavaScript">
    >
    >
    > function formHandler(form){
    > var URL =document.form.site.options[document.form.site.selectedIndex].value;
    > window.location.href = URL;}
    > </script>
    >
    > <form name="form">
    > <select name="site" size=1 onChange="javascript:formHandler2()">
    > <option value="">Enrollment, Fees, Policies
    > <option value="enrollment.html">Enrollment
    > <option value="ssh_policies.html">School Policies & Fees
    > <option value="schedule.html">Group Class Schedule
    > </select>
    >
    > Thank
    >
    > Ken
    >


    Why aren't you ending your OPTION tags?
     
    Jimmy, Feb 25, 2006
    #2
    1. Advertising

  3. ken

    Toby Inkster Guest

    Jimmy wrote:

    > Why aren't you ending your OPTION tags?


    He is. (Tags end with ">", which he has used.)

    If you meant "why aren't you closing your OPTION elements" (with
    </option>), I'm guess that it's because the closing tag for the OPTION
    element is optional in HTML.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Feb 25, 2006
    #3
  4. ken

    Toby Inkster Guest

    ken wrote:

    > <SCRIPT LANGUAGE="JavaScript">


    The "language" attribute has been obsolete for quote some time. Use:

    <script type="text/javascript">

    > function formHandler(form){
    > var URL =document.form.site.options[document.form.site.selectedIndex].value;
    > window.location.href = URL;}


    Nasty. Use:

    function formHandler ()
    {
    var sel = document.getElementById('site');
    var url = site.options[site.selectedIndex].value;
    window.localtion.href = url;
    }

    > </script>
    >
    > <form name="form">
    > <select name="site" size=1 onChange="javascript:formHandler2()">


    Replace these two with:

    <form action="redirect.php" method="GET">
    <div>
    <select name="site" id="site" onchange="formHandler();">

    > <option value="">Enrollment, Fees, Policies
    > <option value="enrollment.html">Enrollment
    > <option value="ssh_policies.html">School Policies & Fees


    "&" here should be replaced with "&amp;".

    > <option value="schedule.html">Group Class Schedule
    > </select>


    Now add:

    <noscript>
    <input type="submit" value="Go">
    </noscript>
    </div>
    </form>

    And create "redirect.php" to handle those visitors who have Javascript
    disabled. Here's a basic "redirect.php".

    <?php
    $url = $_GET['site'];
    if (!preg_match('#http://#', $url))
    $url = "http://{$_SERVER['HTTP_HOST']}/{$url}";
    header("Location: $url");
    ?>

    It assumes that your host supports PHP.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Feb 25, 2006
    #4
  5. Jimmy wrote:

    >> <option value="schedule.html">Group Class Schedule


    > Why aren't you ending your OPTION tags?


    <!ELEMENT OPTION - O (#PCDATA) -- selectable choice -->
    ^
    |
    End tag is optional


    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Feb 25, 2006
    #5
  6. ken wrote:

    > I have the follow javascript.


    (Typical HTML 3.2, JS dependant select based "Jum Mmenu" type stuff)

    > Is there anyway of making it more cosmetically more appealing?


    Scrap it. Replace it with a list of links and style them.

    http://www.cs.tut.fi/~jkorpela/forms/navmenu.html is a good explanation as
    to why such menus are not a good tide which also discusses the alternatives
    and explains how to minimise the damage if you do with that technique.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Feb 25, 2006
    #6
  7. On 25/02/2006 09:03, Toby Inkster wrote:

    [snip]

    > Use:
    >
    > function formHandler ()
    > {
    > var sel = document.getElementById('site');


    If one is to use the getElementById method, it should be feature tested,
    first.

    > var url = site.options[site.selectedIndex].value;
    > window.localtion.href = url;


    There are errors in both of those statements.

    > }


    function formHandler() {
    var sel, url;

    if (document.getElementById
    && (sel = document.getElementById('site'))
    && (url = sel.options[sel.selectedIndex].value)) {
    location.href = url;
    }
    }

    Better yet:

    function goTo(sel) {
    var url = sel.options[sel.selectedIndex].value;

    if (url) {
    location.href = url;
    }
    }

    <select name="site" onchange="goTo(this);">
    <!-- ... -->
    </select>

    [snip]

    > Now add:
    >
    > <noscript>
    > <input type="submit" value="Go">
    > </noscript>
    > </div>
    > </form>


    However, the button should be a required part of the widget[1].

    [snip]

    Mike


    [1] Subject: Re: how to go to a new url onChange from select
    box
    Newsgroup: comp.lang.javascript
    Date: 2004-09-22 11:50:14 GMT
    Message-ID: opsep8lkuox13kvk@atlantis

    <http://groups.google.co.uk/group/comp.lang.javascript/msg/f5d0d4b48ef4056b>

    --
    Michael Winter
    Prefix subject with [News] before replying by e-mail.
     
    Michael Winter, Feb 25, 2006
    #7
  8. ken

    Jimmy Guest

    David Dorward wrote:
    > Jimmy wrote:
    >
    >>> <option value="schedule.html">Group Class Schedule

    >
    >> Why aren't you ending your OPTION tags?

    >
    > <!ELEMENT OPTION - O (#PCDATA) -- selectable choice -->
    > ^
    > |
    > End tag is optional
    >
    >



    Sorry, I haven't read the HTML DTD for a while. I think it seems messy
    to do it that way though.
     
    Jimmy, Feb 25, 2006
    #8
  9. In article <44004dd2$0$12175$5a62ac22@per-qv1-newsreader-
    01.iinet.net.au>, says...
    > David Dorward wrote:
    > > Jimmy wrote:
    > >
    > >>> <option value="schedule.html">Group Class Schedule

    > >
    > >> Why aren't you ending your OPTION tags?

    > >
    > > <!ELEMENT OPTION - O (#PCDATA) -- selectable choice -->
    > > ^
    > > |
    > > End tag is optional
    > >
    > >

    >
    >
    > Sorry, I haven't read the HTML DTD for a while. I think it seems messy
    > to do it that way though.


    Why is sending a reduced amount of downladable content messy?

    --

    Hywel
    http://kibo.org.uk/
     
    Hywel Jenkins, Feb 25, 2006
    #9
  10. ken

    Jimmy Guest

    Hywel Jenkins wrote:
    > In article <44004dd2$0$12175$5a62ac22@per-qv1-newsreader-
    > 01.iinet.net.au>, says...
    >> David Dorward wrote:
    >>> Jimmy wrote:
    >>>
    >>>>> <option value="schedule.html">Group Class Schedule
    >>>> Why aren't you ending your OPTION tags?
    >>> <!ELEMENT OPTION - O (#PCDATA) -- selectable choice -->
    >>> ^
    >>> |
    >>> End tag is optional
    >>>
    >>>

    >>
    >> Sorry, I haven't read the HTML DTD for a while. I think it seems messy
    >> to do it that way though.

    >
    > Why is sending a reduced amount of downladable content messy?
    >


    the code looks messy to me when tags aren't closed.
     
    Jimmy, Feb 26, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mcdeveloper
    Replies:
    1
    Views:
    4,211
    mcdeveloper
    Jun 13, 2006
  2. CRON
    Replies:
    24
    Views:
    200,859
    Adrienne Boswell
    Jun 20, 2006
  3. Mark Rae

    JavaScript or not JavaScript

    Mark Rae, Sep 5, 2006, in forum: ASP .Net
    Replies:
    36
    Views:
    1,101
    Paul Sture
    Sep 9, 2006
  4. Nathan Sokalski
    Replies:
    4
    Views:
    591
    PJ on Development
    Nov 8, 2007
  5. francisco lopez
    Replies:
    2
    Views:
    267
    Hywel Jenkins
    Dec 30, 2004
Loading...

Share This Page