View Full Version : Simple form Q
This is the code for the form..
<form>
<select
onChange="if(this.selectedIndex!=0)
self.location=this.options[this.selectedIndex].value">
<script language="javascript" src="../tech/drop7.js"></script></form>
This is the "drop7.js"
document.write('<option value="" selected>Select a Region<option value="national.html">National<option value="franklinh.html">Franklin<option value="ham1.html">Hamilton<option value="northh.html">NorthHarbour<option value="otara.html">Otara<option value="papat.html">Papatoetoe<option value="tga_h.html">Tauranga</select>');
When I test through Doctor html (http://www2.imagiware.com/RxHTML/) I get ..
"select tag needs a closing tag"
and...
"Form does not have an action defined"
The form seems to work well on all browsers so far.
If I was to add the </select> where would it go?
What would the "action" be?
Thanks in advance
Tonz:cool:
boxer_1
07-16-2002, 09:26 PM
Hi Tonz,
Try this code, it's essentially the same as yours with a few minor modifications. Some validators will be thrown when you use document.write. I validated it through HTML Tidy and there were only a few things it picked-up on (can't remember them all now as I sort of did this in a hurry...lol). The code seems to work fine when I tested it as well:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Testing...</title>
</head>
<body>
<form name="myForm" action="#">
<select onchange="if(this.selectedIndex!=0) self.location=this.options[this.selectedIndex].value">
<script language="javascript" type="text/javascript">
document.write('<option value="" selected>Select a Region<option value="national.html">National<option value="franklinh.html">Franklin<option value="ham1.html">Hamilton<option value="northh.html">NorthHarbour<option value="otara.html">Otara<option value="papat.html">Papatoetoe<option value="tga_h.html">Tauranga');
</script>
</select>
</form>
</body>
</html>
Any better or did I mess it up more by being hasty :D ?
boxer_1
07-16-2002, 11:04 PM
Just to give you another option, here's another version (a little different) you could try out:
<html>
<head>
<title>Testing...</title>
<script language="JavaScript" type="text/javascript">
destination = new Array ("","national.html","franklinh.html","ham1.html","northh.html","otara.html","papat.html","tga_h.html");
function region(pick){
if (pick != 0)
location.href = destination[pick];
}
</script>
</head>
<body>
<form>
<select onChange="region(this.selectedIndex);">
<option>Select a Region</option>
<option>National</option>
<option>Franklin</option>
<option>Hamilton</option>
<option>NorthHarbour</option>
<option>Otara</option>
<option>Papatoetoe</option>
<option>Tauranga</option>
</select>
</form>
</body>
</html>
Accomplishes essentially the same purpose, perhaps a little easier to work with ;) .
premshree
07-17-2002, 03:59 AM
It is always better to close a tag. You should close the tag. Many times even if you don't close a tag, your page may render correctly but not on all browsers. As far as the form action, it is only required if you need server-side processing of the form. You can leave it as action=""
Boxer.
Many thanks, looks great.
I want to keep the external script is so that when a new region is added, I don't have to go through every page that has the form on, and update it. (obviously), so I think your first mod, will do the job just great.
Having the </select> on the other side of the .js was one I should have guessed.
Thanks agin
Tonz
:thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.