Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    Code for radio button

    Good day!

    I never used radio button. Now I need to add radio button in my webpage. Radio button 1 is mother and radio button 2 is child. Is it in my database it is only 1 field or separate field one for mother and one for child?

    Kindly give me a code for radio button.

    Thank you...

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Code:
    <form>
    <input type="radio" name="sex" value="male" /> Male<br />
    <input type="radio" name="sex" value="female" /> Female
    </form>
    find more with google.

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,380
    Thanks
    263
    Thanked 32 Times in 31 Posts
    not sure im understanding what you said about db, but here is a sample of a radio code input form you can modify if you need to..

    Code:
    <form action="result.php" method="post">
      Answer 1 <input type="radio" name="ans" value="mother" /><br />
      Answer 2 <input type="radio" name="ans" value="child"  /><br />
        <input type="submit" value="submit" />
    </form>
    hope that helps

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by durangod View Post
    not sure im understanding what you said about db, but here is a sample of a radio code input form you can modify if you need to..

    Code:
    <form action="result.php" method="post">
      Answer 1 <input type="radio" name="ans" value="mother" /><br />
      Answer 2 <input type="radio" name="ans" value="child"  /><br />
        <input type="submit" value="submit" />
    </form>
    hope that helps
    I want is if the user choose mother it should save in the database. and also the user could not click both radio button.

    Thank you

  • #5
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,380
    Thanks
    263
    Thanked 32 Times in 31 Posts
    by default radio buttons are designed to only allow one choice only, do you already have a table set up in your db for this value to be written to.

  • #6
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by durangod View Post
    by default radio buttons are designed to only allow one choice only, do you already have a table set up in your db for this value to be written to.
    Yes I have...

  • #7
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by poyzn View Post
    Code:
    <form>
    <input type="radio" name="sex" value="male" /> Male<br />
    <input type="radio" name="sex" value="female" /> Female
    </form>
    find more with google.
    A user's choice is in the $_POST['sex'] variable if your form method is post.
    if user checks male radio button then $_POST['sex'] == 'male'

  • Users who have thanked poyzn for this post:

    newphpcoder (12-10-2010)


  •  

    Posting Permissions

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