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 7987761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:14:30+00:00 2026-06-04T12:14:30+00:00

This is a bit complex so I hope I word this right. I have

  • 0

This is a bit complex so I hope I word this right.

I have a form that loads a list of options and starts with one static input:

<span id="keyword_list_out" class="input"><input class="keys margin-bottom" type="text" name="keywords[]" />

When the page is loaded an Ajax call displays additional input fields that belong to the list such as:

<span class="field-wrapper"><input class="keys" type="text" name="keywords[]" value="Option One" /><a class="remove-keyword" href="javascript:void(0);"><img src="images/icons/cross-button-icon.png" /></a></span>
<span class="field-wrapper"><input class="keys" type="text" name="keywords[]" value="Option Two" /><a class="remove-keyword" href="javascript:void(0);"><img src="images/icons/cross-button-icon.png" /></a></span>

These options are prepended to the top of the first static input field ID: keyword_list_out.

The user can dynamically add more input fields and they can remove existing fields.

All of this so far works fine. My problem is accessing the data contained within the input fields. I need to be able to perform three functions once the form is submitted:

  1. If the user has removed an option I need to remove this from the database
  2. If the user has added a field I need to insert this into the database
  3. If the user changes the value of an existing field I need to update this in the database

I can access the data within the input fields by using the input name ‘keyword_name[]’ as an array, and then I can loop through the array.

However this does not address existing options that have a specific ID number. I can assign ID numbers to the fields that were loaded from the Ajax call, however the static field and user added fields wont have ID numbers, as these arent necessary. These fields will simply be inserted into the database.

So I guess my question is how would I go about determining which existing option belongs to what ID number in the database. I should add that the options are not uniquely named.

I considered something such as:

  1. Provide ID numbers only for the Ajax loaded fields
  2. Upon submit loop through each input and prepend the ID to the end of the name value using a delimiter the user wont provide. IE: Option Two—1
  3. With PHP looping through the array and exploding the array value where it matches ‘—‘
  4. If a match was found on ‘—‘ update the database, else insert into the database

Any thoughts?

UPDATE

I have divided the input fields into two arrays: existing_options[] and new_options[].

In my Jquery script prior to posting i have added:

var existing_options = $('input[name=existing_options]').attr('value');
var new_options = $('input[name=new_options]').attr('value');

The Ajax data being sent is:

'existing_options[]=' + existing_options + '&new_options[]=' + new_options;

However PHP is returning that these values are strings and not arrays. Missing something here….

  • 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-04T12:14:32+00:00Added an answer on June 4, 2026 at 12:14 pm

    I would suggest on using an auto increment id on the database side. When you load the page, have the id placed like so <span class="field-wrapper" id="$row[id]"> and than when deleting use:

    $('.remove-keyword').on('click', function(){
        var id = $(this).parents('span').attr('id');
        place ajax post here with data sent being this id.
    });
    

    And basically it’ll be the same for adding a keyword, except use ajax to post to your script, and use mysql_insert_id(); in your script as a returning id than dynamically create the next row.

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

Sidebar

Related Questions

I have a bit complex to explain issue that I have ran into: I
Okay so this is a bit complex but I need to loop through this
Sorry if this question seems a bit complex but I think its all related
This bit of code comes with new classes that are subclasses of UITableViewController... -
How do I change this bit of code so that I only allow pdf
I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
This will take a bit of explanation so I hope I don't lose everyone
This is a bit complex and I really don't now if it is possible.
This is a bit complex. I've created an array (NSArray) called pointsOfInterest. The elements
I have a question for which I suspect the answer is a bit complex.

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.