# Javascript: Editable Select Menu



## AdamP (Dec 29, 2005)

I'm working on a form for a client that I'm trying to make as painless to use as possible. One thing I'm trying to add is an editable select function. What it will be used for is selecting cities that job sites are in, instead of making them add the city manually or just have an input box i would like them to be able to type in a new city and have it automatically saved to the select box for future use. So far I have found several scripts that allow them to be editable but none that will save the new option for use later. If anyone knows of a javascript I can use for this or can help me in creating one I would greatly appreciate it. Thanks.


----------



## covert215 (Apr 22, 2006)

You would probably need to save to a database and recall from there. I remember someone using JS to insert a text box into a select menu...You would probably need to use php to call from a table and insert it into JS and insert that into a select menu

javascript is client-side, so there is no saving


----------



## AdamP (Dec 29, 2005)

covert215 said:


> You would probably need to save to a database and recall from there. I remember someone using JS to insert a text box into a select menu...You would probably need to use php to call from a table and insert it into JS and insert that into a select menu
> 
> javascript is client-side, so there is no saving


Thanks for the reply, I should have added a little more to it. I know that it will need to be database driven, i just don't know how to do it.


----------



## AdamP (Dec 29, 2005)

A little more information that might help, I don't really care how it works whether it be a prompt window, an input box that appears or if the select menu itself allows the edit as long as i can get it to work, i would rather that the select menu is editable just to make it a little cleaner but anything will work. Also covert215 I truly appreciate your quick reply I have posted this same request on two other sites over the past 2 days and so far you are the only one to reply.


----------



## covert215 (Apr 22, 2006)

It is a rough question...

Do you know the javascript part? If so, the php part is easy.


----------



## AdamP (Dec 29, 2005)

yeah i have pretty much got the javascript part done, i just don't know how to make it save to the db. a problem that i have with that though is how to make it show up as a selectable option without refreshing the entire page to pull from the db, is it possible for me to set it in say a div and just refresh that?


----------



## haswalt (Nov 22, 2004)

the way i would have done it was have the text input for the new city and the select visible.

then when submitting send the data to a php page with ajax, this will save the city to your database.

then call another function in javascript to call a hp page and grab the data from the databae, then update our select box. this way we can save a new city, and simultaneously update the select field without reloading the page please see links below on ajax and search google for php and mysql.

http://www.w3schools.com/ajax/default.asp

http://www.petefreitag.com/item/515.cfm

Thanks,

Harry


----------

