Forum Moderators: open

Message Too Old, No Replies

Use clientside code if possible, else use serverside

         

dvprez

9:47 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Hello, this is my first post, I'm hoping someone can help me.

I have 2 dropdown boxes. The value of the first one determines the values of the 2nd. Example: States and Cities.

So when a user selects a state from the first dropdown, the appropriate cities are populated in the second dropdown.

What I would like to do, is populate the second dropdown using clientside code if the users browser can accept it, otherwise, get the info from the server.

I'm pretty sure the validation controls do something like this, but I was unable to find out how. I also searched the forums here, but couldn't find anything.

Avoiding the roundtrip to the server would help a lot.

Anyone know how to do this? or point me in the right direction?

If anyone wants to see the page I'm referring to it's <snip>

Thanks - Don

[edited by: engine at 5:41 pm (utc) on Mar. 19, 2005]
[edit reason] No urls, thanks. See TOS [webmasterworld.com] [/edit]

TheNige

11:35 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Well, if you brought every city over from the first time and populating jscript array on the client, you could then change the drop down boxes depending on the value of the first. Depending on the amount of cities you will be bringing over, this may or may not be a good idea.

Another option is that you can call webservices via jscript so you could do that then parse the xmldocument that is returned and load the drop down list with cities. This would not require typical "round-trip" but would happen behind the scenes on the client side, but still accessing the server each time the 1st drop down is changed.

dvprez

11:55 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



I have the javascript arrays, and it's not cities, it's metroareas - maybe upto 20 for each state, I just used cities and an easy to understand example.

The question though remains. How to check if the users browser will allow me to do this on the clientside and if not to perform it serverside?

mattglet

12:12 am on Mar 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try setting a javascript cookie on a page used before your dropdown page. On the dropdown page, use ASP to check for this cookie. If the cookie isn't there, handle accordingly.

You may encounter problems with people that don't accept cokkies, but this should put you in the right direction.