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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:56:04+00:00 2026-06-17T07:56:04+00:00

I have a MySQL table which looks like this: ID OPTION 1 First 2

  • 0

I have a MySQL table which looks like this:

ID   OPTION
1    First
2    Second

The user sees the following:

<div id="options">
 <select>
  <option value="1">First</option>
  <option value="2">Second</option>
 </select>
</div>

I would like the user to have the option to insert into the table, as follows:

<div id="add">
 <input type="text" name="newOption" placeholder="Your own option">
 <input type="button" value="Add">
</div>

It would then select their newly-added option:

<div id="options">
 <select>
  <option value="1">First</option>
  <option value="2">Second</option>
  <option value="3" selected>Third</option>
 </select>
</div>

As the above code is part of a page which contains other form elements the page can’t be reloaded, otherwise the data they’ve already typed will disappear. So I’d like to use jQuery.

EDIT: I have tried the following but it adds rows twice, sometimes even four times, for reasons I cannot fathom!

$("#button").click(function(){
 var test = $("#<?php echo $selectName; ?>").val();
 var dataString = 'select=<?php echo $select; ?>&selectName='+ test;

 $.ajax({
type: "POST",
url: "optionAdd.php",
data: dataString,
cache: false,
success: function(html){
 $("#<?php echo $select; ?>List").load("optionList.php?select=<?php echo $select; if ($_GET[required] == "no") { echo "&required=no"; } ?>");
     }
  });
});

The reason for the PHP above is I want to use multiples of this code on the same form and so I’m using GET to select the options, as it were.

  • 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-17T07:56:06+00:00Added an answer on June 17, 2026 at 7:56 am

    You would need to send an AJAX request to server with the new data and get an ID returned for this new option. Once the ID is received you can create the option with the new ID as value and the user defined text

    $('#add button').click(function(){
         /* get value from previous input*/
        var newOpt=$(this).prev().val();
         /* make AJAX "POST" request*/
        $.post( 'path/to/server/file', { newOption: newOpt}, function( newId ){
             /* ajax successfully completed, add new option*/
             $('#options select').append('<option value="'+ newId +'">'+newOpt+'</option>');
        });
        return false; /* prevent browser default handling of button click*/
    }) 
    

    At server receive the data as you would a form field with name="newOption" ie $_POST['newOption'] and send back a new ID as text

    Alternatively you could send back all the options as html in sort order you want and replace all the options in the select.

        /* ajax to replace all options with html from server*/
        $.post( 'path/to/server/file', { newOption: newOpt}, function( response ){
             /* ajax successfully completed, add new option*/
             $('#options select').html( response);
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this mysql table called comments which looks like this: commentID parentID type
I have a table which looks like this: mysql> SHOW COLUMNS FROM Users; +------------+--------------+------+-----+---------+----------------+
So, I have a mysql table that looks roughly like this, where the first
I have a MySQL Table which looks like: (unique_id, uid_data1, uid_data2, sorting_data1, sorting_data2) This
I have a MySQL table that looks like this: my_number my_unique_text_field in which, my_number
I have a large MySQL table which looks like this: job_number time_on time_off 111
I have a table which looks like this: mysql> SELECT * FROM Colors; ╔════╦══════════╦════════╦════════╦════════╦════════╦════════╦════════╗
I have a MySQL Table that looks like this: The SQL to create the
For example, I have a table which looks like this : id | name
I have a table which looks like this: CREATE TABLE `library_mix` ( `lib_mix_id` VARCHAR(64)

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.