0

can anyone please suggest , how to add new option to drop down list (using select tag in html) so that user can enter the new value and on submit it should be appended to the existing list ..i am able to populate it's option list via DB dynamically and it's working properly

i am having 5 drop down mutually exclusive category lists in a single table row and i am providing them some initial options.Now i want that if the list contains user's required option then user can select from existing one ...else it should be able to add a new entry to that list & it should be simultaneously updated in DB on submit.

1
  • hiii, finally it's done. i used following function as- function abc() { var myoption = document.createElement("option"); //works with both mozilla and IE myoption.text ="mytext"; myoption.id="mytext"; myoption.name="mytext"; myoption.value ="mytext"; //Probably, the sID stuff document.getElementById("drop_1").options.add(myoption); } & so on within loop. thanks to all . Commented Apr 16, 2013 at 6:27

2 Answers 2

1

Follow this steps

  1. As you are populating the drop down from databse . So its better to add the value in database only.

  2. I think your user will be entering the value in a text box. So on submit call a method or servlet which can be used to add the value in the database field from which you are populating the drop down.

  3. After updation make your servlet to return on the same page.

  4. Now you can see your new option in the drop down.

Update on further problem explaination

For your problem do one thing

  1. Give a text box in last option of each dropdown.

  2. Select an event in which after the new value entered by user in that text box an java script function can be triggered line onmouseout.

  3. In that function call get the text value .

  4. Now call your servlet or method or whatever you are using to update the db with value value in the column corresponding to that drop down using Ajax or normally.

  5. Refresh the page.

Sign up to request clarification or add additional context in comments.

10 Comments

i am having 5 drop down mutually exclusive category lists in a single table row and i am providing them some initial options.Now i want that if the list contains user's required option then user can select from existing one ...else it should be able to add a new entry to that list & it should be simultaneously updated in DB on submit.
@Okk Woner_boy_111 wait its my lunchtime. I will get back to you in just few mins
@Kk Apply this strategy and get back to me if you are getting any problem any where.
@Wonder_boy_111 is it done if you have any problem in doing that ask here to me so that everyone searching on this portal can get the benefit of our discussion.
@Nikhil...no it's not working !!! even text box are not being displayed at the end of list
|
1

hiii, finally it's done. i used following function as-

function abc()
{
    var myoption = document.createElement("option"); //works with both mozilla and IE
    myoption.text ="mytext";
    myoption.id="mytext";
    myoption.name="mytext";
    myoption.value ="mytext"; //Probably, the sID stuff

    document.getElementById("drop_1").options.add(myoption);
}

& so on within loop. thanks to all .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.