Forum Moderators: open
"I'm having trouble using location.href as part of a javascript function in IE (I'm using XP and IE6). I can get it to work in Firefox (both for PC and Mac).
I've searched both this site and others on the internet, and the closest thing that I've found was this bug from MS, but I'm not using anchor tags.
Any help would be appreciated.
Here is a sample code to show the error (the actual code is different, but this code also shows the same error).
<html>
<head>
<script type="text/javascript">
function sendtopage(){
var Page = "new_page"
//comment out alert. Does not work prior to location.href
//alert("You are being forwarded");
document.location.href=(Page + ".htm");
alert("You are being forwarded");
} // end of sendtopage()
function check(){
var hash= document.login.password.value;
var hash_sha1 = "a";
if (hash == "") {
alert ("Nothing entered");
}
else if ( hash == hash_sha1) {
sendtopage();
}
else {
alert ("Incorrect. Please type the letter a");
}
} // end of check()
//sendtopage();
</script>
</head>
<body>
<form name='login'>
<h4>Enter "a" to be sent to a new page<br>
<input TYPE='password' NAME='password' SIZE=15 MAXLENGTH=15><br>
<input TYPE='submit' VALUE='Login' ONCLICK='check()'>
<input TYPE='reset' value='Clear'>
</form>
</body>
</html> "
I agree that the original post brings up other very important details so I thank you for linking to it.
More and more people are disabling JS these days.
- Use a type="submit" button as in the above script.
- Do your JS processing in the onsubmit event of the form. Return false to prevent the form from being submitted.
- Specify an action attribute on the form (it is a reqd attrib afterall) "not_logged_in.html" that provides a simple message to the user (only viewed if JS is not available).
At least this way the non-JS user is not left clicking the type="button" without anything happening.
More and more people are disabling JS these days.
Can you support this claim with a source? stats? Or is it just a hunch-slash-observation?
perhaps more JS-disabled devices are hitting the internet, but are people really turning off javascript? then they can't use Google Maps or Facebook, or anything AJAXified.
My theory is that only web developers and foil hat wearers turn off javascript.
Most of the end users of my clients are Internet dopes, they don't know or care about this stuff and many of them indeed wear tinfoil hats. They turn everything off and browse in fear. If I had to put a number to it, I'd say at least 10% of the users of my client's sites. These stats show your mileage may vary [w3schools.com]. 5% can be a large number of users.
I make it a habit to build Javascript independence into it, but every now and then I miss one . . . and get caught every time. To a client, even one order without proper data is enough. "Get it fixed!"
Building systems that work with or without Javascript is just a Good Idea. If you're going to take time to build Javascript, it only takes a little more time to build it so the overall system doesn't fail. Code as ye may, it's up to you.
To return to the topic, specifically the sub-title of this thread, a submit button will always submit, a button type will not.
Edit: Apologies to those that misinterpret my post. In the interest of accessible web pages, building good Javascript is only part of the task, you would hope to build a page that works with or without it. There are easy ways to do that, and these comments are offered to supplement the use of Javascript, not discourage it.
Previous razing over Javascript dependence [webmasterworld.com].
I take an "all or none" approach. I either work extra-hard to make an entire site totally independent with "progressive" JS features, or I say "blast it" (loose translation) and go for broke with JS as a functional requirement.
This thread is evolving beyond a "submit vs button" debate. Maybe we should take this discussion up in a new post. rocknbil if you're inclined, I'll let you have the honours :)