Log in

View Full Version : Help Validating XHTML this Javascript Form



Markxxx
04-12-2008, 03:34 AM
I got this Javascript form for a combo box, it works fine but I like to have my stuff validate for XHTML 1.0 strict

Here is the link to the script

http://javascriptkit.com/script/cut185.shtml

Works great, as usual I stuck a link to the javacript into the webpage so I didn't have to worry about most of the javascript so I was left with this

<form name="jumpy">
<p><select name="example" size="1" onChange="gone()">
<option value="http://www.cnet.com">Cnet</option>
<option value="http://www.cnn.com">CNN</option>
<option value="http://www.geocities.com">Geocities</option>
</select>

<input type="button" name="test" value="Go!"
onClick="gone()">
</p>
</form>

I know you have to us lowercase for the XHTML to validate, how would you arrange this to validate? The name tag is depreciated but I was told to use ID but I'm not using this right cause it doesn't work

I'd appreciate any help

THanks

coothead
04-12-2008, 10:44 AM
Hi there Markxxx,

try it like this...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
//<![CDATA[
var df;
window.onload=function() {
df=document.forms[0];
df[0].onchange=function(){
gone(this.value);
}
df[1].onclick=function(){
gone(df[0].options[df[0].selectedIndex].value);
}
}
function gone(url){
location.href=url;
}
//]]>
</script>

</head>
<body>

<form action="#">
<div>
<select>
<option value="http://www.cnet.com">Cnet</option>
<option value="http://www.cnn.com">CNN</option>
<option value="http://www.geocities.com">Geocities</option>
</select>
<input type="button" value="Go!"/>
</div>
</form>

</body>
</html>


coothead

Markxxx
04-13-2008, 05:26 AM
Thanks the script does work and validates fine, one question, I only want the onclick, I don't want the onchange.

I have my javascript book here, but no matter what I do, even when I remove the whole thing it keeps going to the site as soon as I touch the drop down box.

LOL

It shouldn't be this hard but I am not getting something. Thanks for the help

mark :)

coothead
04-13-2008, 08:23 AM
Hi there Markxxx,

I did not know whether you required the onchange or the onclick handler, so I allowed for both options in the coding. ;)
Simply remove the highlighted snippet from the script...


<script type="text/javascript">
//<![CDATA[
var df;
window.onload=function() {
df=document.forms[0];
df[0].onchange=function(){
gone(this.value);
}
df[1].onclick=function(){
gone(df[0].options[df[0].selectedIndex].value);
}
}
function gone(url){
location.href=url;
}
//]]>
</script>

...to remove the onchange handler.

coothead

Markxxx
04-14-2008, 09:30 PM
Thank you I swear I did that before and it didn't work...LOL

Maybe the page was cached or something. Oh well it works great now.

Thanks for helping me I appreciate it

coothead
04-14-2008, 09:49 PM
No problem, you're welcome. ;)