Welcome Guest, Not a member yet? Register   Sign In
pass two values from checkbox
#1

I want to post of textvalue+checkbox value into the form

<input type="checkbox"id="mycheck2" name="certid[]" value="2" class="cbx"  > 

<input type="number" id="primaryincome2"  min="0"  max="999" name="noc">

I want to get the values like 

1_1
2_1
3_1
4_2

the first value from checkbox and second value from textbox (no of copies)
Reply
#2

I think this is the 3rd thread where I'm trying to explain to you that form fields must have unique names or names that return values as an array, like certid[]. You must do the same with the element named "noc". Change that into "noc[]".

Now, when you submit the form, be aware that only checked checkboxes are being posted, as well as input fields that are not disabled. I guess you only want a value of the input field, if the checkbox that belongs to it is checked, right?

In your controller:
PHP Code:
$certids $this->input->post('certid');  //here you leave the [ ] out!
$nocs $this->input->post('noc'); 
$result arrray();
foreach (
$certids as $index=>$certid) {
 
  $result[] = $certid '_' $nocs[$index];
}
echo 
'<pre>';
print_r($result);  //this will show the list of 1_1, 2_1 etc. 
echo '</pre>'
Reply
#3

(09-01-2018, 08:15 AM)Wouter60 Wrote: I think this is the 3rd thread where I'm trying to explain to you that form fields must have unique names or names that return values as an array, like certid[]. You must do the same with the element named "noc". Change that into "noc[]".

Now, when you submit the form, be aware that only checked checkboxes are being posted, as well as input fields that are not disabled. I guess you only want a value of the input field, if the checkbox that belongs to it is checked, right?

In your controller:
PHP Code:
$certids $this->input->post('certid');  //here you leave the [ ] out!
$nocs $this->input->post('noc'); 
$result arrray();
foreach (
$certids as $index=>$certid) {
 
  $result[] = $certid '_' $nocs[$index];
}
echo 
'<pre>';
print_r($result);  //this will show the list of 1_1, 2_1 etc. 
echo '</pre>'
thanks a lot.its working perfectly.
Reply
#4

Maybe this will help, check boxes and radio buttons have no meaning if empty ( un-checked ).

PHP: Get Values of Multiple Checked Checkboxes
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB