471,092 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

MSIE Incompatibility: Selection by changing <li> style attribute

Hello everybody! I've just registered to this forum and yet got a question. :)

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:
<script language="javascript" type="text/javascript" src="components/FileBrowser.js"></script>

<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>
And so on.

The SelectFile() function in FileBrowser.js as well as it's main part looks like:
Expand|Select|Wrap|Line Numbers
  1.  /* # GLOBAL declarations */
  2.  var oldSelection = 0;
  3.  var Nothing=null;
  5.  /* ## Selecting file */
  6.  function SelectFile(File_ID) {
  8.         // fill the 'insert' form component
  9.         document.forms["selection"].selected.value=File_ID;
  11.         // deselect previous selection (if any)
  12.         if(oldSelection) {
  13.                 document.getElementById(oldSelection).style.background='';
  14.         }
  16.         // select current choice
  17.         document.getElementById(File_ID).style.background='#A5D8A7;';
  19.         // return new variable
  20.         oldSelection = File_ID;
  21.         return oldSelection;
  22.  }
Can any of the experts here tell me what did i make wrong? I'll be really thankful for any of help. Thanks!

PS. Sorry for my english. :)
Jun 1 '06 #1
2 2267
Is my problem that hard to solve?
Jun 4 '06 #2
16,027 Expert Mod 8TB
The semi-colon will cause problems:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(File_ID).style.background=  '#A5D8A7';
Also, IDs should not start with a number.
Jun 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Randall Sell | last post: by
5 posts views Thread by toylet | last post: by
8 posts views Thread by Udo Marx | last post: by
6 posts views Thread by capricious | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.