mwl707 Posted September 17, 2009 Share Posted September 17, 2009 This is part of my code for selecting items for a list of equipment. When the user clicks on a div box the function allocate is called. This changes the class from truck100grey to truck100 which effectively changes the colour from grey to black . Now when the item is first clicked it turns the image to black. The problem is this only works once and after that the page is unresponsive. Can anyone tell me what i am doing wrong please ? <style type="text/css"> .truckbox {width: 120px ; height:50px; } .truck100 { position: relative; width: 120px; height:33px; background-image:url(black%20artic.jpg); z-index:0; } .truck100grey { position: relative; width: 120px; height:33px; background-image:url(gray%20artic.jpg); z-index:0; } </style> <script> function allocate(trk) { scr = document.getElementById('1001') a = scr.className if (a="truck100") { scr.setAttribute("class", "truck100grey") }; if (a="truck100grey") { scr.setAttribute("class", "truck100") }; } </script> </head> <body> <table align="center" cellspacing="1" cellpadding="1" width="480px" border="1" > <tr> <td class="truckbox"><div class="truck100grey" id="1001" onClick="allocate('1001')" ><font color="white">i100-1</div> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Zane Posted September 17, 2009 Share Posted September 17, 2009 change your script to this <br /> function allocate(theID) {<br /> <br /> scr = document.getElementById(theID);<br /> <br /> a = scr.className;<br /> <br /> if (a=="truck100") {<br /> scr.setAttribute("class", "truck100grey");<br /> }<br /> <br /> if (a=="truck100grey") { <br /> scr.setAttribute("class", "truck100");<br /> }<br /> <br /> }<br /> Quote Link to comment Share on other sites More sharing options...
mwl707 Posted September 17, 2009 Author Share Posted September 17, 2009 Worked a treat ! - thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.