Click to See Complete Forum and Search --> : Ready for a stupid question?... window.location


blue77
June 16th, 2005, 02:26 PM
Thanks for any help.. i'm going nuts...

in the 'head' of the html code I have...

<script language="JavaScript">
function answer() {

x = "";


x = document.ans.text.value;


if (x==correct answer){

window.location=x + '.htm';
}
else {
window.open(x + '.htm');
}

}
</script>

in the body I have...

<form name=ans onsubmit="answer()">
<input type=text name="text" size="25">
<div align="center"><center><p><input type="submit" value="Submit"></p>
</form>



What I want this to do... when I get the 'correct answer' I want the page to go to x.htm ... when I get the incorrect answer I want a popup of x.htm...

the 'logic' works (that is the java script knows the answer.. and compare the values... when it gets the wrong answer a popup DOES occur... and NOTHING happens when I get the right answer...

if i switch the pop up code and the 'redirect' code... I get a pop up just fine with the correct answer.. and nothing happens with the incorrect answer...

why am I not being redirected? what am I doing wrong?

does any of that make sense?

I'm guessing there is some issue with me calling the window.location function inside another function, being called by the 'onsubmit' function... i'm guessing you can't redirect that way...

any insight would be very helpful

Dr. Script
June 16th, 2005, 03:15 PM
Try adding return [and a space] before answer() in the onsubmit event handler. Then use this:<script type="text/javascript">

function answer() {
var x = document.ans.text.value;
if (x==correct answer) {
window.location.href = (x + '.htm');
}
else {
window.open(x + '.htm');
}
return false;
}

</script>That might work ....

Dr. Script

blue77
June 16th, 2005, 03:24 PM
Dr Script you are my HERO ;)

Thank you VERY VERY VERY much.. that was driving me nuts

Dr. Script
June 16th, 2005, 06:05 PM
Glad I helped :D

blue77
June 17th, 2005, 09:34 AM
Second silly question... without looking at the bit patterns and making the uppermost bit be ignored....

how can I make sure that if people enter a text value of say 'yes' that when I am checking for logic any variation of 'yes' will work (ie YES, Yes, YEs, YeS, etc)?

Does javascript have such a function that I simply haven't found?

From my code specifically...

<script type="text/javascript">

function answer() {
var x = document.ans.text.value;
if (x==correct answer)
</script>


I want the x == correct answer to return true (or 1 or however we want to discribe it), no matter the number of capital or lowercase letters

Dr. Script
June 17th, 2005, 02:35 PM
(string.toLowerCase() == "yes") -- the condition to use.

Dr. Script