I want to get radio button value, can Someone Help me?? pleasee???? :(

Discussion in 'PHP' started by greatthings, Nov 23, 2011.

  1. #1
    <?PHP echo "<script>

    function getRadioValue(id) {
    var radioBtn = document.getElementById(id);
    var a = radioBtn.value;


    }

    </script>
    ";

    echo '
    <form action="" method="post">
    <input type="radio" id="btn1" name="radio" value="value1" onClick="Javascript:getRadioValue(this.id)"/>
    <input type="radio" id="btn2" name="radio" value="value2" onClick="Javascript:getRadioValue(this.id)"/>
    <input type="radio" id="btn3" name="radio" value="value3" onClick="Javascript:getRadioValue(this.id)"/>
    <input type="submit">
    </form>
    ';

    ?>
    <?php
    $radio = $_POST['radio'];
    if ($radio == 'checked'){
    echo "$radio";}
    ?>


    i'm new to php, all i want is to get the value of the radio button when clicked and print it automatically.
    how can i do that>>???


    I really need help :( im tired and retless
     
    greatthings, Nov 23, 2011 IP
  2. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #2
    Hi,

    I'm not sure what you need the Javascript for? I would remove that and also remove any pure html from your <?php tags. Something like this for the html:

    <form action="" method="post">
    <input type="radio" name="radio" value="value1"/>
    <input type="radio" name="radio" value="value2"/>
    <input type="radio" name="radio" value="value3"/>
    <input type="hidden" name="submitted" value="1"/>
    <input type="submit"/>
    </form>
    HTML:
    Then the php code:

    if(isset($_POST['submitted']))
    {
        echo $_POST['radio'];
    }
    PHP:
    I *think* that should work. (although completely untested!)
     
    mfscripts, Nov 23, 2011 IP
  3. greatthings

    greatthings Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thnx mfscripts :)

    can we do it without submitting?

    when the radio button is clicked, the value of the radio button is printed automatically.

    hmmmmmmmmmmmmmm.....
     
    greatthings, Nov 24, 2011 IP