July 7, 201412 yr Hi there, i have tow text filed along with two text box. please see attached pic. check box1 text filed 1 check box2 text filed2 the is two page. the index.php page contains the forms with checkbox. and there is another page called new new.php. sucessfully after fuling the form /s the page submit the data to page new.php. but what i want is... if the check box 1 is selected then text filed 1 data will submit. not the text field 2 data. or if check box 2 selected the text field 2 data will submit. not the textfiled1 data. How can i do this?? any help in this issue? advance thanks here is my code index.php <html> <body> <form action="new.php" method="post"> <table width="582" height="149"> <tr> <td width="68"><label> <input type="checkbox" name="abeer1" id="abeer1"> </label></td> <td width="502"><label> <input type="text" name="name1" id="abeerf1"> </label></td> </tr> <tr> <td><label> <input type="checkbox" name="abeer2" id="abeer2"> </label></td> <td><label> <input type="text" name="name2" id="abeerf2"> </label></td> </tr> </table> <input type="submit"> </form> </body> </html> new.php <html> <body> Hello <?php echo $_POST["name1"]; ?> <p> Hello <?php echo $_POST["name2"]; ?> </body> </html> Edited July 7, 201412 yr by abeer
July 7, 201412 yr Change the checkbox to a radio like so <html> <body> <form action="new.php" method="post"> <table width="582" height="149"> <tr> <td width="68"> <label> <input type="radio" name="abeer" id="abeer" value="1"> </label> </td> <td width="502"> <label> <input type="text" name="name1" id="abeerf1"> </label> </td> </tr> <tr> <td> <label> <input type="radio" name="abeer" id="abeer" value="2"> </label> </td> <td> <label> <input type="text" name="name2" id="abeerf2"> </label> </td> </tr> </table> <input type="submit"> </form> </body> </html>Then in your php code use something like this $name = ($_POST['abeer'] == 1?$_POST['name1']:$_POST['name2']); If you want me to explain anything just ask Edited July 7, 201412 yr by D4Y0
July 7, 201412 yr Author many thanks for your reply. but what i need... suppose we have 10 text filed or more then 10 with check box or radio button. every textfiled come along with chekbox or radio button. if we checked the chekbox or radion button for any of the text filed then data of the text of the certain textfiled will submit only. not other text fileld data will submit.
July 7, 201412 yr You can use javascript to do that something like this http://jsfiddle.net/pG66K/1/ Or you could do this via PHP use the same sort of HTML as i posted above with radio buttons $name = $_POST['name'.$_POST['abeer']]; Edited July 7, 201412 yr by D4Y0
July 9, 201412 yr You can use javascript to do that something like this http://jsfiddle.net/pG66K/1/ Or you could do this via PHP use the same sort of HTML as i posted above with radio buttons $name = $_POST['name'.$_POST['abeer']]; I agree
Create an account or sign in to comment