Passing textfiled data by selecting checkbox

Hi there,

i have tow text filed along with two text box.

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 thankstextbox.jpg

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 code

<html>
<body>

Hello <?php echo $_POST[“name1”]; ?> <p>
Hello <?php echo $_POST[“name2”]; ?>
</body>
</html>

Can’t you just test the value of the check boxes, and ignore the text from the field where the checkbox isn’t ticked?


<?php
if ($_POST['abeer1']=="on") {
// do whatever you need with textbox 1
} else {
// do whatever you need with textbox 2
}
?>

And/or use a radio button, so that the user can only select one of the two selections - allowing them to tick both boxes will be confusing, a radio button will make it clear that only one text entry will be used. Or you could use a drop-down and a single text box.