PDA

View Full Version : refresh a dropdown when new element is added


ungovernable
04-12-2008, 11:14 AM
i'm not sure if this can be realized only with php, this might take a little javascript but oh well i think this belongs under the php forum


I have a dropdown with a list of items. These items are comming from a table in my database.

Just right under the dropdown there is a iframe where the users can fill in a form, and when sent it will add a new item to the dropdown (by adding an entry in the same table where the dropdown is taking the items from)

So far everything is good, but the only problem is that the dropdown isnt automatically refreshed when new items are added (when the form is sent). So the users usually end up thinking it didn't work and their item wasn't added.

After the users have added an item, they MUST refresh the page with the form where the dropdown is in, thus losing all datas they entered in the other steps of the form

How could i auto-refresh that dropdown so my users don't have to refresh the page after adding a new element?

thanks a lot

NancyJ
04-12-2008, 11:39 AM
PHP can't refresh the page for you. Does the form need to be in an iframe? If it were on the same page as the dropdown the page would automatically be refreshed by submitting the form data.

ungovernable
04-12-2008, 11:55 AM
yes, i can put it in the same form

really, the dropdown is gonna be auto-refreshed? i'm going to try this

ungovernable
04-12-2008, 12:00 PM
oh well, i just realized if i put it on the same page when the page is submitted it will refresh the same page anyway.... so this doesn't solve the problem

maybe is it possible to refresh the dropdown with javascript or dhtml ?

Inigoesdr
04-12-2008, 12:12 PM
Yep, it would take Javascript/AJAX.

ungovernable
04-12-2008, 12:16 PM
could anyone point me to the right direction, give me a tutorial, or even better a part of code to help me?

i guess this should be moved to the javascript forum then

A1ien51
04-12-2008, 03:34 PM
why don't you add it before submitting the form?


var newOpt = new Option("text","value");
var sel = parent.document.formName.selectName;
sel.options[sel.options.length] = newOpt;


Eric

wonko
04-12-2008, 09:44 PM
Here's a very simple chat room that is powered off of AJAX
http://www.linuxuser.at/wiki_old/index.php?title=Most_Simple_Ajax_Chat_Ever

I'm sure you could reverse engineer it so that when someone "posts a message" it writes to your SQL and then the "chat area" could be refitted to display the menu.