Need refresh for almost-nested selects in a form

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Need refresh for almost-nested selects in a form

Post 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? :(
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Moved to Client Side.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Post 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>
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Post by jolinar »

Thanks Pickle, that got it working :D
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Make sure that you have a back up in case Javascript is turned off by the user.
Post Reply