Announcement

Collapse
No announcement yet.

checkboxes - only one ticked at once

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • checkboxes - only one ticked at once

    Hi,

    Could someone help me out with the code for my mailing list form please? The form consists of an email input field and two checkboxes, one which allows you to subscribe to the list and another one which allows you to unsubscribe. At the moment both checkboxes can be ticked, which obviously doesn't make sense because you can't subscribe and unsubscribe at the same time. Here's my HTML code...

    PHP Code:
     <form name="txtlist" action="grapevine/index.php" method="get">
              <
    br>
                      
              <
    table border="0" align="center" cellpadding="4" cellspacing="0" class="asb">
                 <
    tr><td width="427">
    <
    input type="text" name="email" value="email address" size="20" maxlength="100" onFocus="if (this.value=='email address') this.value=''" onBlur="if (this.value=='') this.value='email address'" class="forms">
    <
    input type="submit" name="sub" value="go" class="forms">
                            <
    input type="checkbox" name="type" id="type_sub" value="sub" checked>
                    <
    label for="type_sub"Subscribe</label>
                    &
    nbsp;&nbsp;<input type="checkbox" name="type" value="unsub" id="type_unsub">
                    <
    label for="type_unsub"Unsubscribe</label>
    </
    td></tr>
     </
    table>
    </
    form
    Any help would be much appreciated, thanks.

  • #2
    Checkboxes are so that you can make multiple selections, what you are looking for is a radiobutton, then you can select only one.

    Comment


    • #3
      I didn't try this but take a look

      HTML Code:
      <form name="txtlist" action="grapevine/index.php" method="get">
      		 <br>
       
      		 <table border="0" align="center" cellpadding="4" cellspacing="0" class="
      asb">
      			 <tr><td width="427">
      <input type="text" name="email" value="email address" size="20" maxlength
      ="100" onFocus="if (this.value=='email address') this.value=''" onBlur="if (this.
      value=='') this.value='email address'" class="forms">
      <input type="submit" name="sub" value="go" class="forms">
      						<input type="radio" name="type" id="type_sub" checked value="
      sub" >
      				<label for="type_sub"> Subscribe</label>
      				&nbsp;&nbsp;<input type="radio" name="type" value="unsub" id="
      type_unsub">
      				<label for="type_unsub"> Unsubscribe</label></td></tr>
      </table>
      </form> 

      I didn't see your reply Floris sorry
      To be or not to be... Where the hell is the question????
      My psychiatrist told me I was crazy and I said I want a second opinion. He said okay, you're ugly too

      Live vBulletin 4.2.0 Multilingual * Alpha/Beta vB 4 - vB 5 Tier 1A
      CentOS 6.2 - Apache:2.2.15(Apache2Handler) - PHP:5.3.3 - MySQL:5.1.61
      Xampp/Win-XP - Apache v2.2.21(Apache2Handler) - PHP:5.3.8 - MySQL:5.5.16

      Comment


      • #4
        Thanks for the replies. I was using radio buttons before, but wanted to switch to checkboxes purely for aesthetic reasons. If it's not possible to use them in this way I can change the form back to the way it was before.

        Comment


        • #5
          yes theres a way but for the good of it I just can't think or remember how.. but there is a way to use it with checkbox, when you check one the other gets unchecked..

          sorry can't help you at this point
          To be or not to be... Where the hell is the question????
          My psychiatrist told me I was crazy and I said I want a second opinion. He said okay, you're ugly too

          Live vBulletin 4.2.0 Multilingual * Alpha/Beta vB 4 - vB 5 Tier 1A
          CentOS 6.2 - Apache:2.2.15(Apache2Handler) - PHP:5.3.3 - MySQL:5.1.61
          Xampp/Win-XP - Apache v2.2.21(Apache2Handler) - PHP:5.3.8 - MySQL:5.5.16

          Comment


          • #6
            Hi Stryker

            I did this for a member of ours that had a situation that he had to do the same, check this out:
            http://webxpertz.net/forums/showthre...hlight=Discuss
            Later
            Keith

            Webxpertz Community for Webmasters & Developers

            Comment


            • #7
              You should just use radiobuttons, seeing as this is exactly what they were intended for.

              Comment


              • #8
                Thanks very much. I'll give it a go and see which I prefer. Beetle's comments make sense, but even so it's good to know there's a solution to this 'problem'.

                Comment

                Loading...
                Working...
                X