1

I have a form that looks like the following:

<form action="results.php" method="get">

<input type='checkbox' name='batch[]' value='1'>
<input type='text' name='job_id[]' value='111'>

<br>

<input type='checkbox' name='batch[]' value='1'>
<input type='text' name='job_id[]' value='999'>

</br>

<input type='submit' name='submit' value='Submit'>

</form>

enter image description here

In the example below I have only selected the row with 999 in the textbook.

The results are displayed in the results.php page which code looks like this:

<?php

$batch = $_GET['batch'];
$job_id = $_GET['job_id'];

foreach($job_id as $key => $value) {

    echo $batch[$key]." ";
    echo $value."<br>";
    }

?>

The above code displays like this:

1 111
999

As you can see the 1 (checkbox) is next to 111. I want to be able to allow send across the job_id from the row selected.

Hopefully I have explained the problem well enough.

Many thanks,

John

1

2 Answers 2

1

add index number in html :

<form action="viewport.php" method="get">

    <input type='checkbox' name='batch[1]' value='1'>
    <input type='text' name='job_id[1]' value='111'>

    <br>

    <input type='checkbox' name='batch[2]' value='1'>
    <input type='text' name='job_id[2]' value='999'>

    </br>

    <input type='submit' name='submit' value='Submit'>

</form>



<?php
if(isset($_GET['batch'])) {
  $batch = $_GET['batch'];
  $job_id = $_GET['job_id'];
  foreach($job_id as $key => $value) {
    if(isset($batch[$key])) {
      echo $batch[$key]." ";
      echo $value."<br>";
    }
  }
}
?>

It will only print:

1 999

because only second check-box is checked.

Sign up to request clarification or add additional context in comments.

Comments

0

Give textbox value to checkbox. Same value set to checkbox and textbox.

Javascript

<form action="test5.php" method="get">

<input type='checkbox' name='batch[]' value='111'>
<input type='text' name='job_id[]' value='111'>

<br>

<input type='checkbox' name='batch[]' value='999'>
<input type='text' name='job_id[]' value='999'>

</br>

<input type='submit' name='submit' value='Submit'>

</form>

PHP

<?php
$batch = $_GET['batch'];
$job_id = $_GET['job_id'];

foreach($batch as $key => $value) {
    echo $value."<br>";
    }

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.