Page 1 of 1

Need refresh for almost-nested selects in a form

Posted: Tue Sep 19, 2006 1:50 pm
by jolinar
Does anyone know how to refresh a document when a select option element is clicked? And information needs to be carried over. I'm guessing I sound a little vague so I'll explain what I'm trying to do instead.

I'm working on a gallery administration page. I'm using html select elements in forms. What I'm trying to achieve is a system where the first box can be used to select an album. The second will present a list of photos (well their titles). Of course the problem is that php is a server side scripting language which makes this a little tricky (well to be, but what can I say - I'm a numpty). I've seen this kind of functionality on websites before, but I'm at a loss as to how to achieve this.

(I'm not sure if this is cross-posted, but I'm guessing the fact that this is based on HTML, and possibly use of javascript - this ,ay be the best place for it)

Any ideas? :(

Posted: Tue Sep 19, 2006 2:06 pm
by RobertGonzalez
Moved to Client Side.

Posted: Tue Sep 19, 2006 2:30 pm
by pickle
You can tie javascript into the action of the value changing in a select box

If you want to go to a different page:

Code: Select all

<select onChange = "window.location = 'http://myserver.com/gallery?id='+this.value">
<option value = 'tapioca'>Tapioca pudding gallery</option>
<option value = 'rock_salt'>Rock salt gallery</option>
<option value = 'down_pillows'>Down pillows gallery</option>
</select>

Posted: Tue Sep 19, 2006 4:27 pm
by SpecialK
Javascript seems to be the way to go.

Aside from the redirect, you can also use the form to do a document.submit() to the page of your choosing. This way you at least have the option of passing values in a post or a get.

I've done this several times with company select lists to generate a location selection server side from the DB

Code: Select all

<form name='searchForm' action='' method='post'>
<select name=companies onchange='document.searchForm.submit();'>
</form>

Posted: Wed Sep 20, 2006 12:13 pm
by jolinar
Thanks Pickle, that got it working :D

Posted: Wed Sep 20, 2006 1:23 pm
by RobertGonzalez
Make sure that you have a back up in case Javascript is turned off by the user.