I want to add to conditions to one of my statements - is that possible?
Something like "if (this) box is checked and you put (this) word in the text box and click on submit, you will go to (this) page..."
Thanks!
| SitePoint Sponsor |
I want to add to conditions to one of my statements - is that possible?
Something like "if (this) box is checked and you put (this) word in the text box and click on submit, you will go to (this) page..."
Thanks!
Try this:
The bold parts are what you need to edit:
<script>
function getit() {
if ((document.former.check.checked == true) && (document.former.word.value == "What the textbox value should be in order to move to the page")) {location.replace("Website to go to")}
else {alert("Another function goes here")}
}
</script>
<form name="former">
<input type="checkbox" name="check" value="ON">
<input type="text" name="word">
<input type="button" onClick="getit()" value="submit">
</form>
Last edited by Disk-t; Aug 23, 2001 at 12:43.
Hey Disk-t, that looks good - I've added a couple more radio buttons but this isn't working - what have I done wrong?
<script>
function getit() {
if ((document.former.check.checked == true) && (document.former.word.value == "test")) {location.replace("http://www.cnn.com")}
if ((document.former.check.checked == true) && (document.former.word.value == "test1")) {location.replace("http://www.msnbc.com")}
if ((document.former.check.checked == true) && (document.former.word.value == "test2"))
{location.replace("http://www.espn.com")}
}
</script>
<form name="former">
<p>
<input type="radio" name="check" value="ON">
<input type="radio" name="check" value="ON">
<input type="radio" name="check" value="ON">
</p>
<p>
<input type="text" name="word">
<input type="button" onClick="getit()" value="submit">
</p>
</form>
Thanks again!
This should work:
The bold sections were edited:
<script>
function getit() {
if ((document.former.check1.checked == true) && (document.former.word.value == "test")) {location.replace("http://www.cnn.com")}
else if ((document.former.check2.checked == true) && (document.former.word.value == "test1")) {location.replace("http://www.msnbc.com")}
else if ((document.former.check3.checked == true) && (document.former.word.value == "test2"))
{location.replace("http://www.espn.com")}
else{alert("Another function has occured which is not currently on the list above in the script!")}
}
</script>
<form name="former">
<p>
Check box 1: <input type="radio" name="check1" value="ON">
</p>
<p>
Check box 2: <input type="radio" name="check2" value="ON">
</p>
<p>
Check box 3: <input type="radio" name="check3" value="ON">
</p>
<p>
<input type="text" name="word">
<input type="button" onClick="getit()" value="submit">
</p>
</form>
Last edited by Disk-t; Aug 23, 2001 at 13:23.
Thanks - I actually had something similar to that (without the use of "else") but the problem I was getting (and this happens with your code) is that you can click on all three of the radio buttons and they all stay "on" - do you need to create some sort of an array with them???
Thanks...
When you have multiple "if"s in your script, the first "if" stays the same, but the others need to be changed to "else if". Also, it is recommended that you have an "else" (if an unexpected combination happens) in your script.
Try this:
<script>
function getit() {
if ((document.former.check1.checked == true) && (document.former.word.value == "test")) {location.replace("http://www.cnn.com")}
else if ((document.former.check2.checked == true) && (document.former.word.value == "test1")) {location.replace("http://www.msnbc.com")}
else if ((document.former.check3.checked == true) && (document.former.word.value == "test2"))
{location.replace("http://www.espn.com")}
else{alert("Another function has occured which is not currently on the list above in the script!")}
}
</script>
<form name="former">
<p>
Check box 1: <input type="radio" name="check1" value="ON" onClick="check2.checked=false; check3.checked=false">
</p>
<p>
Check box 2: <input type="radio" name="check2" value="ON" onClick="check1.checked=false; check3.checked=false">
</p>
<p>
Check box 3: <input type="radio" name="check3" value="ON" onClick="check1.checked=false; check2.checked=false">
</p>
<p>
<input type="text" name="word">
<input type="button" onClick="getit()" value="submit">
</p>
</form>
Thanks Disk-t. That did it!





Great job Disk-t...
Thanks for helping out.
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
Bookmarks