Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spot The Error In This Little Javascript

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
The following is in the head of an html document:

<script language=&quot;javascript&quot;>
function chg_box('item_name', switch)
{ {
item_name.style.backgroundColor = '999999';
}
if(switch == 1)

else
{
item_name.style.backgroundColor = '993333';
}
}

</script>



In the body of the html document I have this:

<div class=&quot;item&quot; id=&quot;Gold River&quot; onmouseover=&quot;chg_box('Gold River', 1);&quot; onmouseout=&quot;chg_box('Gold River', 0);&quot;>Gold River</div>



When I open the page I get an error
line 12 character 21 identifier expected
which corresponds to the first ' in the function definition in the head of the document.

If I mouseover or mouseout on the div I get this error
line 30 character 1 object expected
which corresponds to the beginning of the line with the div on it.

Please let me know if you have any suggestions.
 
Changing your function to this will work too(in IE5+ , not sure about IE4):

function chg_box(item_name, stat)
{
if(stat == 1)
{
document.getElementById(item_name).style.backgroundColor = '#999999';
window.status = item_name;
}
else
{
document.getElementById(item_name).style.backgroundColor = '#993333';
window.status = '';
}
}
 
What works? Which solution was the one that solved the problem? It would help others to know what worked for you.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top