Hi all,
I am posting this as a last resort: I am truly baffled.
My dynamic form isn't behaving quite as I want. Essentially, when I choose an option from one select list, it populates a second select list. When I choose and option from the second select list, it is supposed to populate a textarea. It works for a couple of the options but not all.
Relevant JS code:
Relevant HTML code:
Sorry for posting so much code - I stripped out all of the extras.
The code works for:
Calgary Sheraton Suites Au Claire
Toronto Royal York Hotel
For all others, where there is a place associated with the City, the address field won't populate when a place is selected. I went through all the code and verified that each if statement in the getAddress(myform,place) function matches up with the corresponding values of the places that are set in the getPlaces(myform,city) function.
I am at my wit's end here, and would be extremely grateful for any help/advice!
![[banghead] [banghead] [banghead]](/data/assets/smilies/banghead.gif)
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)
Cheers!
Laura
I am posting this as a last resort: I am truly baffled.
My dynamic form isn't behaving quite as I want. Essentially, when I choose an option from one select list, it populates a second select list. When I choose and option from the second select list, it is supposed to populate a textarea. It works for a couple of the options but not all.
Relevant JS code:
Code:
<script language="javascript" type="text/Javascript">
function clearFields(myform){
myform.place.selectedIndex = 0;
myform.address.value = "";
}
function getPlaces(myform,city) {
var index = city;
myform.place.options.length=0;
if (index == 0){
myform.place.options[0] = new Option('Places will appear after selecting a city');
}
if (index==1){
myform.place.options[0] = new Option("Choose a place:");
myform.place.options[1] = new Option("Sheraton Suites Calgary Eau Claire",1);
}
if (index==2){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==3){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==4){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==5){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==6){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==7){
myform.place.options[0] = new Option("Choose a place:");
myform.place.options[1] = new Option("Queen's Ottawa Classroom Facility",9);
}
if (index==8){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==9){
myform.place.options[0] = new Option("Choose a place:");
myform.place.options[1] = new Option("Royal York Hotel",2);
myform.place.options[2] = new Option("Sheraton Centre Toronto",3);
}
if (index==10){
myform.place.options[0] = new Option("Choose a place:");
myform.place.options[1] = new Option("Hotel Vancouver",8);
}
if (index==11){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==12){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==13){
myform.place.options[0] = new Option("Choose a place:");
}
if (index==14){
myform.place.options[0] = new Option("Choose a place:");
myform.place.options[1] = new Option("Donald Gordon Conference Centre",4);
}
if (index==15){
myform.place.options[0] = new Option("Choose a place:");
myform.place.options[1] = new Option("Hilton Suites Hotel",5);
}
if (index==17){
myform.place.options[0] = new Option("Choose a place:");
myform.place.options[1] = new Option("Delta Toronto East",6);
}
if (index==18){
myform.place.options[0] = new Option("Choose a place:");
myform.place.options[1] = new Option("Delta Meadowvale",7);
}
}
function getAddress(myform,place) {
var myindex = place;
try {
if (myform.place.selectedIndex == -1)
var item_value = 0;
else
var item_value = myform.place.options[myindex].value;
} catch (e) {
var item_value = 0;
}
myform.address.value = '';
if (item_value==1){
myform.address.value = "255 Barclay Parade SW";
}
if (item_value==2){
myform.address.value = "100 Front Street West";
}
if (item_value==3){
myform.address.value = "123 Queen Street West";
}
if (item_value==4){
myform.address.value = "421 Union Street";
}
if (item_value==5){
myform.address.value = "8500 Warden Avenue";
}
if (item_value==6){
myform.address.value = "2035 Kennedy Road";
}
if (item_value==7){
myform.address.value = "6750 Mississauga Road";
}
if (item_value==8){
myform.address.value = "900 West Georgia Street";
}
if (item_value==9){
myform.address.value = "Constitution Square \n350 Albert Street \nSuite 220";
}
}
</script>
Relevant HTML code:
Code:
<form id="add" method="post" action="save.php?tableid=18" onSubmit="return CheckForm(this)">
<select name="city" onChange="javascript: getPlaces(this.form,this.value);clearFields(this.form);">
<option value="xx" selected>Select City</option>
<option value="1">Calgary</option>
<option value="2">Edmonton</option>
<option value="3">Fort McMurray</option>
<option value="13">Halifax</option>
<option value="4">Hamilton</option>
<option value="14">Kingston</option>
<option value="5">London</option>
<option value="15">Markham</option>
<option value="18">Mississauga</option>
<option value="6">Montréal</option>
<option value="7">Ottawa</option>
<option value="8">Regina</option>
<option value="17">Scarborough</option>
<option value="9">Toronto</option>
<option value="10">Vancouver</option>
<option value="11">Windsor</option>
<option value="12">Winnipeg</option></select>
<select name="place" onChange="getAddress(this.form,this.value);"></select>
<textarea name="address" cols="27" rows="3" wrap="PHYSICAL"></textarea>
</form>
Sorry for posting so much code - I stripped out all of the extras.
The code works for:
Calgary Sheraton Suites Au Claire
Toronto Royal York Hotel
For all others, where there is a place associated with the City, the address field won't populate when a place is selected. I went through all the code and verified that each if statement in the getAddress(myform,place) function matches up with the corresponding values of the places that are set in the getPlaces(myform,city) function.
I am at my wit's end here, and would be extremely grateful for any help/advice!
![[banghead] [banghead] [banghead]](/data/assets/smilies/banghead.gif)
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)
Cheers!
Laura