Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:20:42+00:00 2026-06-17T12:20:42+00:00

I am newbie in Codeigniter so I don’t know how to do this. Actually

  • 0

I am newbie in Codeigniter so I don’t know how to do this.
Actually my view page has five rows which I generated through for loop in which each row contain two select boxes and two input boxes. I don’t know how to get these values first in jQuery and then pass into controller. Actually I know how to grab values from a simple textboxes but because I generate them in a loop and give them a separate id, so I don’t know how to get the values in jQuery and then pass to the controller.

This is my view

       <tr>
        <th>Category:</th>
    <th>Items:</th>
       <th>Selling Price:</th>
        <th>quantity:</th>

</tr>

    <?php for ($i = 0; $i < 5; $i++) {

    ?>
    <tr> //Categories
<td><?php echo form_dropdown('cat_id', $records2, '#', 
        "id='category_".$i."'  onchange='getItems(this.value,".$i.")' ");?>
                        </td>
          <!-- Items -->

  <td>form_dropdown('item_id', $records3, '#', "id='items_".$i."'"); ?> </td>
    <!-- end of Items -->



    <td> <?php echo form_input($price); ?></td>

<td><?php echo form_input($quantity); }?></td>

The item options is based on the categories selection, means if I select some option from categories, then the items against categories show in a second select box.

Here is my Javascript for functionality of top two select boxes

    <script type="text/javascript">

function getItems(category_id,index) {

       $("#items_" + index + " > option").remove(); 

    $.ajax({
        type: "POST",
        url: "stockInController/get_Items/"+category_id, 
        success: function(items) 
        {
            $.each(items,function(item_id,item_name) 
            {
                var opt = $('<option />'); 
                opt.val(item_id);
                opt.text(item_name);
                $('#items_'+ index).append(opt); 
            });
        }

    });
}
 </script> 

Now the problem is here; I want to get the values from all the rows and then pass into controller.
This is the javascript for catching and then sending values to controller

  <script type="text/javascript">
 $('#btns').click(function() { //  $("#form").serialize()

Here, I am not doing right, first I don’t know how to get values of item and categories here and then the other thing is how to be able to get multiple textbox values because there are five rows, and the textvalues in which values are filled are to be sent

var item_id = $('#items').val();   
var item_id = $('#items').val();


var price = $('#price').val();
var quantity = $('#quantity').val();




var form_data = {
        cat_id: $('#cat_id').val(),

        quantity: $('#quantity').val(),
        item_id: $('#items').val(),




};


$.ajax({
    url: "<?php echo site_url('salesController/addSales'); ?>",
    type: 'POST',
    data: form_data,
    dataType: 'json',
    success: function(msg) {
        if(msg.res == 1)
        {

            alert("true");
        }
        else{
            alert("false");          
          }


    }
});

return false;
    });


</script>

Here is my controller and I don’t know to get multiple values here also.
Here is the code of what I am doing, I know I am wrong, but I don’t know how to make it right

       $data = array(
            'cat_id' => $this->input->post('cat_id'),

            'item_id' => $this->input->post('item_id'),
            'price' => $this->input->post('sales_date'),
            'quantity' => $this->input->post('sales_bill_no'),

            );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:20:43+00:00Added an answer on June 17, 2026 at 12:20 pm

    In your case, set the name of your input and select elements like this cat_ids[], item_ids[], prices[] and quantities[]. Note the [] at the end of these name (I have changed the name to make it in plural-form, this is just a name convention 🙂 ).

    In the controllers $this->input->post('cat_ids') will return an array named cat_id and contains all your ids, this is the same for $this->input->post('item_ids'), $this->input->post('prices'), … You can use a for loop like this to traverse through all posted values:

    for($i = 0; $i < count($data['cat_id']); $i++)
    {
        $yourItem = array (
            'cat_id' => $data['cat_id'][$i],
            'item_id' => $data['item_id'][$i],
            'price' => $data['price'][$i],
            'quantity' => $data['quantity'][$i],
        );
    }
    

    To send the form data in Ajax uses jQuery you can set your form_data=$('your-form-id').serialize(); instead of building its value by your hand 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a newbie in codeigniter. I want to load jquery on every page.
I am a newbie in CodeIgniter. And would like to know how am I
Excuse me if this is slightly newbie. I have the main view located @
Newbie Q. In my MainViewController, which is the first visible view. I have a
Im newbie here.I have a problem with codeigniter segment() method.I referred 6th segment of
Newbie in testing. I generated a test case using Selenium, and then exported it
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
am newbie to jquery..I have a three steps registration form in which the user
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
How can push a URI like this in CodeIgniter (1.7.1 currently): example.com/seg1/seg2/seg3/seg4/ or example.com/seg1/seg2/

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.