Click to See Complete Forum and Search --> : Jump Menu For State, County Using PHP?


Volitics
07-30-2003, 01:07 AM
I am working on a web site (the web site is for persons to request an insurance quote) where visitors can choose a state then choose a county within that state.

What I am trying to do is install a drop-down menu (or something similar) for the state. Once the visitor chooses the state a list of the counties within that state automatically fill an array in another drop-down menu (without the visitor having to click a "Submit" button) on the same page.

I've seen web pages like that but have never had an occasion to figure out how they work.

I'm trying to figure out how to put all of this on one page - instead of having to design a separate page for each of the fifty states.

My question is: Can I do the above using PHP - or must I use something like JavaScript?

I would appreciate any assistance.

Thank you in advance.

Volitics

Weedpacket
07-30-2003, 02:19 AM
That is a Javascript task; you can tell because it happens on the client, not the server.

Just about any Javascript repository will have several dozen of the things, of varying quality.

The only PHP stuff would be filling out the Javascript arrays, but that's just a matter of writing out "new Array(" and then loop through and echo the entries to make a Javascript array.

Volitics
07-30-2003, 09:55 AM
Weedpacket;

That's what I thought but was not sure.

Thank you for the help.

Best Regards;

Volitics

elToro
07-30-2003, 06:28 PM
I've done similar things many times. Be warned: with the county OPTIONs being populated dynamically, the 'back' button may have an unpredictable effect on that field's value no matter what you do (unless the user hits 'refresh', in which case it is a little more controllable).

Either way, it is indeed a job for JavaScript.

epimeth
07-30-2003, 10:26 PM
and don't expect it to work on netscape...

elToro
07-31-2003, 12:06 PM
Making it work in Netscape shouldn't be a problem. JavaScript was, of course, created by Netscape; and the functionality to populate a SELECT dynamically has been there from the earliest versions of JavaScript. It should work in newer, DOM-compliant browsers (like Mozilla) too.

goldbug
07-31-2003, 12:13 PM
Stick to using document.getElementById(); and it will work in just fine Moz/Netscape 6+, IE 5+ and Opera 6+. Avoid using *any* browser-specific code.

stolzyboy
07-31-2003, 12:15 PM
I have something like that going for our intranet site(its not for states, but it is a drop down, and it jumps and sends the information thru the query string to the next page), and it works in IE, Nutscrape 7, Mozilla Firebird 0.6, and Opera 7.11

bad76
07-31-2003, 12:25 PM
Hi,
in my site i do this into top frame:

<select name="county" ONCHANGE="
x=parent.bottomfrm.location.href;
y=parent.bottomfrm.location.search;
parent.bottom.location.replace(x.substring(0,x.length-y.length)+'?cnt='+this.selectedIndex);">
<? while($row=mysql_fetch_array($res))
echo "<option value='$i++'>".$row["county"]."</option>\n";
?>
</select>


and this into bottom:

...
readfile("county/county_".$cnt.".html"); ?>
...


This work fine in my Netscape4.0, that i use for JS test purpose, and with any recent IE too.
With location.replace we resolve any problem of history.back.

see you