42 users online (0 members and 42 guests)  


  Results 1 to 3 of 3

Related

  1. Help me to check    Forum: Show it off!
    Replies: 3
  1. #1
    Bandion's Avatar
    New User

    Status
    Offline
    Join Date
    May 2009
    Posts
    1

    either or check box

    i am trying to create a checkbox to say if a visitor is here 1st time or not (i need to use checkbox over radio), but i cant seem to get it to uncheck the opposite option. Can anyone point out what I am doing wrong?
    Thanks
    Bandion


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <title>

    </title>
    <script type="text/javascript">

    /* <![CDATA[ * /
    function sumbitForm() {
    if (document.forms[0].salutation.options[0].selected == ""
    || document.forms[0].name.value == "") {
    window.alert("You must enter all form data.");
    return false;
    }
    else
    return true;
    }
    function opposite() {
    if (document.forms[0].newVisit.checked == true) {
    document.forms[0].returnVisit.checked = false);
    }
    else
    if (document.forms[0].returnVisit.checked == true) {
    document.forms[0].newVisit.checked = false);
    }
    }
    /* ]]> */

    </script>
    </head>
    <body>
    <form action="" method="get" enctype="application/x-www-form-urlencoded">
    <p>Please select your gender.</p>
    <input type="radio" name="gender"
    value="male" checked="checked" />Male<br />
    <input type="radio" name="gender"
    value="female" />Female<br />
    <br />
    <select name="salutation">
    <option value="Mr">Mr.</option>
    <option value="Mrs">Mrs.</option>
    <option value="Ms">Ms.</option>
    <option value="none">None</option>
    </select>
    <input type="text" name="firstName" size="15" />
    <input type="text" name="lastName" size="25" />
    <br />
    <br />
    <input type="checkbox" name="visit" checked="checked"
    value="newVisit" onmouseup="opposite()"/>First time visitor<br />
    <input type="checkbox" name="visit"
    value="returnVisit" onmouseup="opposite()" />Returning visitor<br />
    <input type="button" name="submit" value="Submit" />


    </body>
    </html>

  2. #2
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: either or check box

    The problem is that you have two checkboxes that are both called "name". You are referencing them using the value. What you need to do is change the names so that they are different (perhaps change the name to what you have the value set as). At that point it should work.

    Also, I have never had to much luck using onmouseup. I would use onclick instead.

  3. #3
    rangana's Avatar
    Moderator/Allstar

    Status
    Offline
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    317

    Re: either or check box

    Onmouseup event works fine across browsers.

    The main problem why the "opposite()" function isn't firing was that the CDATA islands are erroneous.

    On CDATA opening, remove the extra space which is right after the asterisk. So this part:
    Code:
    /* <![CDATA[ * /
    ...needs to be rectified into:
    Code:
    /* <![CDATA[ */
    Your next thing to get worry of, is to get the script working. I suggest you get Firebug alongside your development. Rectify the script errors, and when you're still stumped, please don't hesitate to get back on us.
    Checkout my porfolio.
    Please click the button when a member helped you.
    Take time to use Forum's Search function.



Tags for this Thread