Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-16-2002, 08:59 PM   PM User | #1
Tonz
Regular Coder

 
Join Date: Jun 2002
Location: Auckland New Zealand
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Tonz is on a distinguished road
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 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
__________________
Beware, the Cybertooth tiger cometh
Tonz is offline   Reply With Quote
Old 07-16-2002, 09:26 PM   PM User | #2
boxer_1
Regular Coder

 
Join Date: May 2002
Location: Maine, USA
Posts: 574
Thanks: 0
Thanked 0 Times in 0 Posts
boxer_1 is an unknown quantity at this point
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:

Code:
<!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 ?
__________________
boxer_1
CodingForums Moderator
"How did a fool and his money get together in the first place?"
boxer_1 is offline   Reply With Quote
Old 07-16-2002, 11:04 PM   PM User | #3
boxer_1
Regular Coder

 
Join Date: May 2002
Location: Maine, USA
Posts: 574
Thanks: 0
Thanked 0 Times in 0 Posts
boxer_1 is an unknown quantity at this point
Just to give you another option, here's another version (a little different) you could try out:

Code:
<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 .
__________________
boxer_1
CodingForums Moderator
"How did a fool and his money get together in the first place?"
boxer_1 is offline   Reply With Quote
Old 07-17-2002, 03:59 AM   PM User | #4
premshree
Regular Coder

 
Join Date: Jun 2002
Location: Mumbai, India
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
premshree is an unknown quantity at this point
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=""
premshree is offline   Reply With Quote
Old 07-17-2002, 08:01 PM   PM User | #5
Tonz
Regular Coder

 
Join Date: Jun 2002
Location: Auckland New Zealand
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Tonz is on a distinguished road
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

__________________
Beware, the Cybertooth tiger cometh
Tonz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:32 AM.


Advertisement
Log in to turn off these ads.