Jump to content

[SOLVED] Toggle a Div Box


mwl707

Recommended Posts

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>

Link to comment
Share on other sites

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 />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.