Dynamic form fields
I have a search form that I want to put different search fields into depending on the country the visitor comes from (which is selected in field 1)
So, if they select Country = USA, they see a form with just a dropdown list of State codes, but if they choose any other country they get a form with ordinary text fields for County/State, Town etc.
Any ideas???
Thanks a bunch
===Toby===
Comments
A 3 part form location selector.
Download this file : http://dailybuzz.net/ee/country/city_state.js
then create a standard html page and include this in between the body code. Make sure the 2 pages are in the same location.
<script type="text/javascript" src="city_state.js"></script>
</head>
<body onload="document.getElementById('region').value = 'North America';document.getElementById('region').onchange();">
<div id="widget">
<form>
Region» <select id='region' onchange="set_country(this,country,city_state)" size="1" name="region">
<option value="" selected="selected">SELECT REGION</option>
<option value=""></option>
<script type="text/javascript">
setRegions(this);
</script>
</select>
Country» <select name="country" size="1" disabled="disabled" onchange="set_city_state(this,city_state)"></select>
City/State» <select name="city_state" size="1" disabled="disabled" onchange="print_city_state(country,this)"></select>
</form>
<div id="txtregion"></div>
<div id="txtplacename"></div>
</div>
<script type="text/javascript">
// document.getElementById('region').value = 'North America';
// document.getElementById('region').onchange();
</script>
Hopefully if all works you should have 3 fields to select the Location, Country and City.
RE: A 3 part form location selector: 99% working
Wow! Thanks, Stephen. After 3 years I'd sort of given up expecting any response to this post... but as it happens it's an issue that has just come round again, so your reply was actually very timely.
I tried it and it's working 99%. There's a test page at http://www.boo-online.com/states.htm. The only problem is that I get JavaScript errors when I select Region or Country. When I select a Region I get:
Line: 304
Char: 2
Error: Object doesn't support this property or method
Code: 0
URL: http://www.boo-online.com/states.htm
When I select a Country I get:
Line: 322
Char: 2
Error: Object doesn't support this property or method
Code: 0
URL: http://www.boo-online.com/states.htm
- although th script actually works fine.
Any suggestions?
Thanks again
===Toby===
Not sure
Hmmm, well I actually tested the script using a .php page - have you tried this? also I have'nt used .htm pages but maybe .html pages might fix it?
RE: Not sure
Well. I tried it, even though I don't know what difference that might make. Created states.php and states.html. Guess what? The same problem...
I think it's a JavaScript issue - could it be anything to do with my browser version (MSIE v6.0.2900)?
Otherwise, maybe it's a scripting problem??
Thanks
===Toby===
You must me logged in to write a comment.