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

  • Home
  • SEARCH
  • 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 6540859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:01:58+00:00 2026-05-25T11:01:58+00:00

I am trying to append some digits to the class names of the elements

  • 0

I am trying to append some digits to the class names of the elements I am trying to dynamically add on a page. The digit that I will append is by getting the number of the existing target element on the page and I am getting it through the jquery function length.

Here is my code:

$("#add_ingr").click(function(){

                var id = $('.save').length + 1;

                var row = '<tr>'
                            +'<td>' 
                                +'<?php $data = array('name' => 'ingr_name[]', 'class' => 'ingr_name'); echo form_input($data); ?>'
                            +'</td>'
                            +'<td>'  
                                +'<?php $data = array('name' => 'ingr_amount[]', 'class' => 'amt'); echo form_input($data); ?>'
                            +'</td>'
                            +'<td>'
                                +'<?php $data = array('name' => 'ingr_unit[]', 'class' => 'unit'); echo form_input($data); ?>'
                                +'<span class="remove">X</span>'
                                +'<span class="save" id="' +count +'">Save</span>' 
                            +'</td>';                                                               
                         +'</tr>';

                $("#ingr_table > tbody").append(row);

            });

I’m having troubles because the var id is of javascript and I wanted to append it in a php array value but I am not successfully running the code because it generates errors when I do something like this:

$("#add_ingr").click(function(){

                var id = $('.save').length + 1;

                var row = '<tr>'
                            +'<td>' 
                                +'<?php $data = array('name' => 'ingr_name[]', 'class' => 'ingr_name_' +id); echo form_input($data); ?>'
                            +'</td>'
                            +'<td>'  
                                +'<?php $data = array('name' => 'ingr_amount[]', 'class' => 'amt_') +id; echo form_input($data); ?>'
                            +'</td>'
                            +'<td>'
                                +'<?php $data = array('name' => 'ingr_unit[]', 'class' => 'unit_' +id); echo form_input($data); ?>'
                                +'<span class="remove">X</span>'
                                +'<span class="save" id="' +count +'">Save</span>' 
                            +'</td>';                                                               
                         +'</tr>';

                $("#ingr_table > tbody").append(row);

            });

Does anybody have a solution for my problem? Thank you very much for those who would help.

  • 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-05-25T11:01:59+00:00Added an answer on May 25, 2026 at 11:01 am

    Do you really need CodeIgniter’s form_input helper?

    function form_input($data = '', $value = '', $extra = '')
    {
      $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
    
      return "<input "._parse_form_attributes($data, $defaults).$extra." />";
    }
    

    As this will just return <input name=$name class=$class/>,
    I guess you can convert it to this.

    var row = '<tr>'
                +'<td>' 
                    +'<input name="ingr_name[]" class="ingr_name_'+id+'"/>'
                +'</td>'
                +'<td>'
                    +'<input name="ingr_amount[]" class="amt_'+id+'"/>'
                +'</td>'
                +'<td>'
                    +'<input name="ingr_unit[]" class="unit_'+id+'"/>'
                    +'<span class="remove">X</span>'
                    +'<span class="save" id="' +count +'">Save</span>' 
                +'</td>';                                                               
             +'</tr>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to dynamically append some objects to a div and then programatically
I'm trying to append a transparent layer to some elements with an edit button
I am trying to append two chars but for some reason I am getting
jsFiddle I'm trying to append some text to a heading that is in a
I have an append query that is trying to append some records to one
hi i'm trying to dynamically append some divs and then use jquery on them
I'm trying to print some Japanese to a page dynamically using jQuery, and it
I am trying append some XML retrieved via a dojo.XHRGet to a dijit.layout.ContentPane .
I'm trying to append some text to a variable in a Makefile for HP-UX's
I'm trying to append a CSS class to a row on RowDataBound. I'm using

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.