PDA

View Full Version : Set drop down list value from hotspot on graphic


Gary Williams
12-01-2002, 08:01 PM
Hi All,

I have a search routine whose values are set by drop down boxes and radio buttons. One of the drop down boxes is a list of UK counties. I want to 'hotspot' every county on the map so that when a county on the map is clicked, the name of the county is automatically set in the drop down box.

I can use the onClick facility in the map's area tag to call a javascript function, no problem, but how do I set the drop down box?

Gary

Graeme Hackston
12-01-2002, 08:29 PM
Not tested

function blah(country) {
for (var i=0;i<document.MyForm.MySelect.options.length;i++) {
if (country == document.MyForm.MySelect.options[i].text) {
document.MyForm.MySelect.selectedIndex = i;
}
}
}

onclick="blah('England')"

Gary Williams
12-02-2002, 04:20 PM
Hi Graeme,

Thanks very much for your help. The code worked fine and I even managed to modify it to use 'getElementById'. I can now trigger a database search function just by clicking on a graphics/map.

Regards

Gary

------------------------------------

<HTML>
<HEAD>
<TITLE>Suppliers</TITLE>

<SCRIPT>
<!--
function county(name) {
for (var i=0;i<document.getElementById("counties").options.length;i++) {
if (name == document.getElementById("counties").options[i].text) {
document.getElementById("counties").selectedIndex = i;
}
}
}
//-->
</SCRIPT>

</HEAD>
<BODY>

<FORM NAME="MyForm">
<SELECT ID="counties" NAME="SEARCH">
<OPTION VALUE=" " SELECTED>County</OPTION>
<OPTION VALUE="">--------</OPTION>
<OPTION VALUE=" ">ALL</OPTION>
<OPTION VALUE="^Aberdeenshire$">Aberdeenshire</OPTION>
<OPTION VALUE="^Angus$">Angus</OPTION>
<OPTION VALUE="^Argyllshire$">Argyllshire</OPTION>
<OPTION VALUE="^Ayrshire$">Ayrshire</OPTION>
</SELECT>
</FORM>

<IMG ID="Picture2" HEIGHT=443 WIDTH=279 SRC="../assets/images/UKcountymap.gif" BORDER=0 ALT="" USEMAP="#map0">

<MAP NAME="map0"><AREA SHAPE=CIRCLE ALT="" COORDS="182,240,18" onClick="county('Angus');"></MAP>

</BODY>
</HTML>

Graeme Hackston
12-02-2002, 10:37 PM
Glad it works. The reason it wasn't test is I converted it from getElementById :D