SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    East Side
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If...and statement?

    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!

  2. #2
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    East Side
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  4. #4
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    East Side
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

  6. #6
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    East Side
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Disk-t. That did it!

  9. #9
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •