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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IF Statement for Radio button

    From HTML form, I have recevied variable part_assy; In PHP form I have two Radio buttons.

    PHP Code:
    <FORM Action="<?php echo $_SERVER['PHP_SELF']?>" Method="POST">
    <input type="radio" name="part_assy" value="Part 1">Part 1<br>
    <input type="radio" name="part_assy" value="Part 2">Part 2<br>
    </FORM>
    I need IF statement to check variable part_assy with value of two Radio buttons. If variable = value of radio button then radio button should be checked.

    Thanks.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think this'll do what you want.
    PHP Code:
    <FORM Action="<?php echo $_SERVER['PHP_SELF']?>" Method="POST"> 
    <input type="radio" name="part_assy" value="Part 1"<?php echo (isset($_POST['part_assy']) && $_POST['part_assy'] == "Part 1" 'checked="checked"' ''); ?>>Part 1<br> 
    <input type="radio" name="part_assy" value="Part 2"<?php echo (isset($_POST['part_assy']) && $_POST['part_assy'] == "Part 2" 'checked="checked"' ''); ?>>Part 2<br> 
    </FORM>

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did try your earlier suggestion of issest, but I am missing something or may be not doing it right.

    I am trying to dynamiclly set the value of Radio button.
    When the page is loaded, the value of $part_assy (which is button1) should be checked with each of the radio buttons.

    If $part_assy is equal to the Value of radio button then radio button should be checked.
    PHP Code:
    <?
    $part_assy 
    "button1";
    ?>
    <form name="form2" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
        <input name="radiobutton" type="radio" value="button1">Text1<br>
        <input name="radiobutton" type="radio" value="button2">Text2<br>
    </form>
    Any help is appriciated. Thanks.
    Last edited by jjdave; 07-21-2005 at 07:02 PM.


  •  

    Posting Permissions

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