I've got some database, that is processed by PHP in a 'while' loop and each element that the loop draws (<li>) gets an unique ID and href to the javascript function, that should change its background color and post the ID to some invisible <input>. Actually it works pretty fine - but not in MSIE (tested on NT5.1 SP2). The debug info is absolutely idiotic and i have no idea how to make the script compatible for both, Gecko and MSIE.
Generated HTML looks like that:
[HTML]
<head>
<script language="javascript" type="text/javascript" src="components/FileBrowser.js"></script>
</head><body>
<div id="vfiles"><ul>
<li id="30">
<a href="#" onClick="SelectFile('30');"><img class="icon" src="images/icons/file_subsite.gif"><div class="names"><span class="name">Some item</span></div></a></li>
<li id="34">
<a href="#" onClick="SelectFile('34');"><img class="icon" src="images/icons/file_subsite.gif"><div class="names"><span class="name">Some other item</span><br><span class="name2">And its sub description</span></div></a></li>
<li id="32">
<a href="#" onClick="SelectFile('32');"><img class="icon" src="images/icons/file_subsite.gif"><div class="names"><span class="name">And another</span><br><span class="name2">With its description</span></div></a></li>
[/HTML]
And so on.
The SelectFile() function in FileBrowser.js as well as it's main part looks like:
Expand|Select|Wrap|Line Numbers
- /* # GLOBAL declarations */
- var oldSelection = 0;
- var Nothing=null;
- /* ## Selecting file */
- function SelectFile(File_ID) {
- // fill the 'insert' form component
- document.forms["selection"].selected.value=File_ID;
- // deselect previous selection (if any)
- if(oldSelection) {
- document.getElementById(oldSelection).style.background='';
- }
- // select current choice
- document.getElementById(File_ID).style.background='#A5D8A7;';
- // return new variable
- oldSelection = File_ID;
- return oldSelection;
- }
PS. Sorry for my english. :)