<?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
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!)
thnx mfscripts can we do it without submitting? when the radio button is clicked, the value of the radio button is printed automatically. hmmmmmmmmmmmmmm.....