javascript - How do i get values of the checked check boxes and perform an action on each of them in codeigniter?

962
<input type="checkbox" value="<? echo $user->roll_no ?>" name ="user[]" /></td>

What does the array 'user' store and how do i perform action on each of the element of the array?? What should be the code in model, view and controller for this??

649

Answer

Solution:

I would use a simple php foreach statement. The array stores the value you're echoing in the html above. Only the checked checkboxes are sent during the form submit.

<?php
    foreach($_REQUEST["user"] as $roll_no){
        //perform action here $roll_no is the variable you need
    }
?>
191

Answer

Solution:

In controller

<?php
function some_function()
{
  $user = $this->input->post('user');
   if(! empty($user))
   {
     foreach($user as $roll_no)
     {
      //ur user roll no value  $roll_no
     } 
   }
 }

People are also looking for solutions to the problem: javascript - How can you pull a PHP value from a table row in JQuery to use later?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.