and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a menu file that I'm wanting to change images when you hover over the <a> tag, or when you press the mouse button. I thought I had it right but when the page loads up it acts like the javascript is malfunctioning. Here is my html tag.
[syntax="html"]
<dt id="menu1" onclick="javascript:show('smenu1');" onMouseOver="javascript:buttonUp('menu1');" onMouseDown="javascript:buttonDown('menu1');" onMouseUp="javascript:buttonUp('menu1');" onMouseOut="javascript:buttonFlat('menu1');">Employees</dt>
function buttonUp(id){
document.getElementById(id).style.background-image='url("images/buttonUp.jpg")';
}
function buttonDown(id){
document.getElementById(id).style.background-image="url('images/buttonDown.jpg')";
}
function buttonFlat(id){
document.getElementById(id).style.background-image="url('images/buttonFlat.jpg')";
}
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
You don't need to put "javascript:" in onclick, onmouseover, etc values. They are javascript constructs so it's not necessary.
If you keep onclick, onmouseover, etc all lowercase, you won't get validation errors
Javascript doesn't know about "background-image". I'll bet you're getting lots of errors about not knowing what the variable 'background' and 'image' are. Change that to 'backgroundImage' & it should work.
I don't see any definition for the show() function.
Why not just use CSS and the a:hover pseudo-element to change the background image. It's much simpler & works with JS turned off.
Last edited by pickle on Mon Jan 22, 2007 2:25 pm, edited 1 time in total.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Ok, that worked. Thanks so much. I was thinking the .style.background-image was used to change the css statement.
Also, how do you tag javascript on here instead of using the code button up above. I used the code button before and my message was edited. Thanks again.
jdhorton77 wrote:Also, how do you tag javascript on here instead of using the code button up above. I used the code button before and my message was edited. Thanks again.
There's a drop down which says "Syntax..."; it works similarly to the "Code" button.