Forum Moderators: open

Message Too Old, No Replies

window.open onclick in multiple select list not working in IE

         

tatorface

6:39 pm on Jul 30, 2008 (gmt 0)

10+ Year Member



First time poster, long time troller....

I have a page that has a large amount of single items to display. The best way I found was to list it within a multiple <select> box. What I need is for a popup window to be called once any given option in the list is selected. An ID will be passed to the popup and it will display the pertinent info that the user requested. I have this working in Firefox 3+, but cannot get it to work in IE 6 or 7.

I searched around the site (and google and other sites) and found this post:
[webmasterworld.com...]
This example shows how to popup a window from a dropdown menu (same principle) when the user was having problems getting it to work in IE as well, but the code on that page does not work as-is and I cannot seem to fix it.

Here is what I have so far. I have removed any personal info:

Javascript:


<SCRIPT LANGUAGE="JavaScript">
function popUp(URL) {
day = new Date();
id = day.getTime();
window.open(URL, id , 'toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=1,width=750,height=600,left = 50,top = 50');
}
</script>

HTML (PHP markup removed):


<SELECT NAME='edit' MULTIPLE SIZE='25' id='edit'>
<option value='Selection Value' onClick="javascript: popUp('http://site.com/page.php?id=$Id')">Selection Name</option>
</select>

Obviously, the result would be to click the "Selection Name" and a popup is returned. Any help would be appreciated.

I have heard that the onClick event does not work when added to an <option> tag in IE, but cannot verify this. If this is true, does someone know of a workaround?

Thanks!

Trace

2:39 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



Hey tatorface,

Your best bet is to use "onchange" on the select, here's a quick example of what you can do;

<select id="edit" multiple size="25" onchange="doSomething(this.options)">
<option value="Selection Value 1">Selection Name 1</option>
<option value="Selection Value 2">Selection Name 2</option>
<option value="Selection Value 3">Selection Name 3</option>
<option value="Selection Value 4">Selection Name 4</option>
<option value="Selection Value 5">Selection Name 5</option>
<option value="Selection Value 6">Selection Name 6</option>
<option value="Selection Value 7">Selection Name 7</option>
<option value="Selection Value 8">Selection Name 8</option>
</select>

<script type="text/javascript">
function doSomething(theIndexes){
i = 0;
while(i<=theIndexes.length) {
if (theIndexes[i].selected) {
//do something
alert(theIndexes[i].value)
}
i++;
}
}
</script>


Hope that helps.

tatorface

3:22 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



Thanks for the response. I actually found a way around this which turned out to be better for me. What I did was remove the <select> completely and used an iframe (uh oh!) that loads much smaller chunks of info based on whatever category the user chooses. This cut down on load times and browser lag once the whole list was loaded. It also made it easier for the user so they wouldn't have to scroll for 19 miles to get to the item they wanted. The iframe uses regular hyperlinks with the popup javascript attached now so an onchange or onclick event is not needed. This is being housed on an intranet so security issues associated with iframes are not much of a concern. Thanks for your help though. I look forward to more of my questions being answered ;)