Help this javascript

K

ken

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
 
J

Jimmy

ken said:
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?
 
T

Toby Inkster

Jimmy said:
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.
 
T

Toby Inkster

ken said:
<SCRIPT LANGUAGE="JavaScript">

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

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>
<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.
 
D

David Dorward

ken said:
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.
 
M

Michael Winter

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>
 
J

Jimmy

David said:
<!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.
 
H

Hywel Jenkins

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top