Jump to content

Add select (dropdown) boxes using jQuery


jenkins

Recommended Posts

Hi,

I need to implement a function that will allow a user to add a <select> (dropdown) box when clicking a button and be able to keep adding a <select> when clicking the button.

I am totally new to jQuery but this is what I have so far:

<label for="characteristic" id="characteristic_label">Add Characteristic</label>
      
<input type="button" id="buttonToAddChar" value="Add" style="cursor:pointer;" />
<div id="newCharacteristic" style="display:block; width:100px;"></div>


<script>
$("#buttonToAddChar").click(function () {
     var newChar = $("<select/>");
     $(newChar).append("<option><?PHP echo "Select from list"; ?></option>");
     $("#newCharacteristic").append(newChar);

});
</script>
 

This does work (screenshot attached) but I need to add the following features:

1. The options for each <select> dropdown should come from a mySQL query (and each additional <select> added should not contain the option chosen in previous <select> dropdowns)

2. Add the option for a user to remove a <select> previously added (I think another function, right?)

3. Submit/save the option chosen in each <select> to a mySQL table (I can do this using a form, but what is the best way to get the option chosen from each dropdown?)

 

Am I going in the right direction?  How difficult is this going to be for a jQuery newbie?  

 

Any help would be greatly appreciated.

Thank you!

 

post-138495-0-84614200-1362308940_thumb.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.