468,510 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,510 developers. It's quick & easy.

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:
[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
  1.  /* # GLOBAL declarations */
  2.  var oldSelection = 0;
  3.  var Nothing=null;
  4.  
  5.  /* ## Selecting file */
  6.  function SelectFile(File_ID) {
  7.  
  8.         // fill the 'insert' form component
  9.         document.forms["selection"].selected.value=File_ID;
  10.  
  11.         // deselect previous selection (if any)
  12.         if(oldSelection) {
  13.                 document.getElementById(oldSelection).style.background='';
  14.         }
  15.  
  16.         // select current choice
  17.         document.getElementById(File_ID).style.background='#A5D8A7;';
  18.  
  19.         // return new variable
  20.         oldSelection = File_ID;
  21.         return oldSelection;
  22.  }
  23.  
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 2224
Hm.
Is my problem that hard to solve?
Jun 4 '06 #2
acoder
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
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.