I have plenty of problems with stuff like this, but this one's embarassing. I'm making an interactive tutorial about HTML5, and I'm having trouble with the coding.
I made a post on my forums about it. You can see it here.

Offline
There are three problems I can see:
* You forgot to close the function (with an } at the end)
* You need to use the .value property of the <input> to get its value
* You need to use the comparison operator == instead of the assignment operator = inside the if.
It should probably look something more like this:
function check() {
var answer = document.getElementById('AnswerBox').value;
if (answer == "<h1>"){
window.location = "scratch.mit.edu";
}
}Try installing a Firefox extension such as Firebug so you can see these kinds of errors yourself in the console. (Chrome has something similar.)
I'd also suggest using a library like jQuery that can handle some stuff for you, like being able to select elements using CSS selectors.
Last edited by blob8108 (2012-05-06 15:59:33)
Offline
blob8108 wrote:
There are three problems I can see:
* You forgot to close the function (with an } at the end)
* You need to use the .value property of the <input> to get its value
* You need to use the comparison operator == instead of the assignment operator = inside the if.
It should probably look something more like this:Code:
function check() { var answer = document.getElementById('AnswerBox').value; if (answer == "<h1>"){ window.location = "scratch.mit.edu"; } }Try installing a Firefox extension such as Firebug so you can see these kinds of errors yourself in the console. (Chrome has something similar.)
![]()
I'd also suggest using a library like jQuery that can handle some stuff for you, like being able to select elements using CSS selectors.
That's a nice suggestion and all, but really, the only problem with this script is the way he did the redirect. He used:
window.location = "scratch.mit.edu";
When he should've used:
window.location.href = "http://scratch.mit.edu/";
Offline
blob8108 wrote:
There are three problems I can see:
* You forgot to close the function (with an } at the end)
* You need to use the .value property of the <input> to get its value
* You need to use the comparison operator == instead of the assignment operator = inside the if.
It should probably look something more like this:Code:
function check() { var answer = document.getElementById('AnswerBox').value; if (answer == "<h1>"){ window.location = "scratch.mit.edu"; } }Try installing a Firefox extension such as Firebug so you can see these kinds of errors yourself in the console. (Chrome has something similar.)
![]()
I'd also suggest using a library like jQuery that can handle some stuff for you, like being able to select elements using CSS selectors.
It works! Thanks! I'm going to look into Firebug, too.

Offline