Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clicking on a county map should highlight the item in list box

Status
Not open for further replies.

greygirl

Programmer
Jun 12, 2002
34
0
0
US
I have a form where I have a list box with all the counties of a state and a link (a map image). On clicking the map opens the map in a popup window.

Upto this I am fine. On clicking one of the counties in the map should highlight the same county in the list box. I am having problems with this.

Please somebody help!!!!!

greygirl

This is part of my code.

javascript code in Original Window:

<script>
function newWindow()
{
mywindow = open('map.htm', 'myname', 'resizable=no, width=400, height=500');
mywindow.location.href = 'map.htm';
if(mywindow.opener == null) mywindow.opener=self;
}

function restart() {
document.mainForm.areaname.options.selectedIndex = mywindow.
mywindow.close();
}

</script>


javascript code in map.htm:

<script>
function copyItem(countyVal)
{
for (var oi=0;oi < opener.mainForm.areaname.options.length;oi++)
{
if (countyVal == opener.mainForm.areaname.options[oi].value)
{
opener.mainForm.areaname.options.selectedIndex == countyVal;
}

}


}


</script>

 
Questions:

1) why mywindow.location.href = 'map.htm'
when &quot;mywindow = open('map.htm', &quot; sets href already

2) what are you trying to accomplish with the
restart() function

3) How are you passing the &quot;countyVal&quot; to your
copyItem() function

4) You should pass an index number to the selectedIndex:
opener.mainForm.areaname.options.selectedIndex == countyVal
- to -
opener.mainForm.areaname.options.selectedIndex == oi

2b||!2b
 
Your questions are legitamate and I have redundancy in the code and so got rid of restart() function and passed an index number to the selectedIndex. But it still does not select the county I chose from the map. The map appears and after I click a county it disappears. No change in the List box items.
Help!
greygirl
 
Sorry,

I sent you a typo!!!

try &quot;...selectedIndex = oi&quot; not &quot;...selectedIndex == oi&quot;

this page demonstrates your application
maybe you can find the answer here.

<html>
<head>
<title>Options Change</title>
<script language=&quot;JavaScript&quot;>
function chg_opt() {
d = document.test;
a = d.vala.value;
for(oi=0; oi<d.testlist.options.length;oi++) {
if(a == d.testlist.options[oi].value){
d.testlist.options.selectedIndex = oi;}
}
}
</script>
</head>
<body><form name=&quot;test&quot;>
<input type=&quot;text&quot; name=&quot;vala&quot; size=&quot;10&quot; value=&quot;val2&quot;>
<select name=&quot;testlist&quot;>
<option value=&quot;val1&quot;>firstitem</option>
<option value=&quot;val2&quot;>secitem</option>
<option value=&quot;val3&quot;>thrirditem</option>
</select>
<input type=&quot;button&quot; value=&quot;Change&quot; onClick=&quot;chg_opt()&quot;>
</form>
</body>
</html>

2b||!2b
 
Thanks for the help. This code works fine in IE.

But in Netscape 7.1, it opens the map window. when i click the states in the map, nothing happens i.e the same state in the list box is not selected.

The error is &quot;opener.mainForm has no properties&quot;
Anybody! any clues! Help!!

greygirl
 

If you change:

Code:
opener.mainForm.areaname.options.selectedIndex

To:

Code:
window.opener.forms['mainForm'].areaname.options.selectedIndex

Does that make a difference?

Dan
 
Dan
Same error. but now the error is window.opener.forms has no properties.
greygirl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top