PDA

View Full Version : submit button uses Onclick but does not validate under w3.org



shyne
09-05-2007, 09:03 PM
Hi

I am using a form which send users to different url when you select an option. Below is my form and the javascript used.


<form name="Iccy" action="">
Sort By: <select name="blah" class="small">
<option value="http://www.mysite.com/jjskkhkjsl.html">Page1</option>
<option value="http://www.mysite.com/blah.html">Page 2</option>
</select>
<script language="javascript">
<!--
function go() {
location=document.Iccy.blah.
options[document.Iccy.blah.selectedIndex].value
}
//-->
</script>
<input type="button" name="test" value="Go!" onClick="go()">
</form>


Now the problem is that when I validate my page using the w3.org it shows error stating that the onClick="go()" used is invalid and cannot be used with the doc type. I do not want to change my doctype or anything else and I want my page to validate since all my pages are validated nicely.
Can someone please give me another alternative to my approach. Any other way of sending user to that url but within a form and also be validate with XHTML1.0

Thanks

boogyman
09-05-2007, 11:12 PM
language has been depreciated...
use


<script type="text/javascript">
___ your code _____


also the variable "go" is used by the language itself so you need to create a new variable you can do something like


function goPlace()

shyne
09-06-2007, 04:17 AM
Thanks alot buddy

codeexploiter
09-06-2007, 06:13 AM
also the variable "go" is used by the language itself so you need to create a new variable you can do something like

I don't think if you override a built-in function with your own it show any error. But it is wise to avoid a built-in function name as you own function name.


<input type="button" name="test" value="Go!" onClick="go()">

You need to put the contents that you've furnished inside the body within the correct container elements like <p>

Moreover you haven't provided the Doctype you've used in your case.

shyne
09-06-2007, 05:50 PM
The actual problem was with onClick being in capital letter C. Changing that into onclick gave no errors while validating.

boogyman
09-06-2007, 06:15 PM
you must be trying to validate it with xhtml.... I would suggest that you do not use the xhtml doctype as it is not supported by IE, and thus you cannot reap the full benefits that it provides, accurately on a consistent basis

shyne
09-07-2007, 02:54 PM
well so far my pages have been validated nicely by XHTML 1.0 doc type. And my pages display fine too on every browser. I am making my website cross browser compatible. So if you saying IE does not support XHTML I would like to know in hat situation? Since everything is fine and validating.

Thanks

boogyman
09-07-2007, 03:45 PM
whether it validates or not, IE doesnt support it. Read this article
http://www.w3.org/2000/07/8378/xhtml/media-types/MSIE6.0SP2