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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Button background image. 1

Status
Not open for further replies.

ChrisQuick

Programmer
Oct 4, 1999
144
US
We have a style for buttons (named btn) that we are using on our forms.
Each button represents a department and when clicked loads that department's two primary pages into a frames. As an onclick event, for each button, we are calling a javascript function to determine which button was click determine which pages to load.

At the same time we would like to change the background image of the button so the user can tell where they are.

The buttons have the background image property set to image1.jpg by default and we want to replace it with image2.jpg


The code we have (and this is abbreveated) is this:
<html><head>
<script language=&quot;javascript&quot;>
function gotoLoc(buttonClicked){
top.parent.main.screenone.location=&quot;intro_&quot;+buttonClicked.value+&quot;.htm&quot;;
top.parent.main.results.location=&quot;employees_&quot;+buttonClicked.value+&quot;.asp&quot;;
buttonClicked.backgroundimage=&quot;images/image2.jpg&quot;;
}
</script>
</head>
<body>

<input type=&quot;button&quot; class=&quot;btn&quot; onclick=&quot;gotoLoc(this);&quot; value=&quot;Dept1&quot; name=&quot;Dept1&quot;>

<input type=&quot;button&quot; class=&quot;btn&quot; onclick=&quot;gotoLoc(this);&quot; value=&quot;Dept2&quot; name=&quot;Dept2&quot;>

</body></html>
 
The question is: Does anybody help determine why it doesn't work??? [sig][/sig]
 
The question is: Does anybody have any ideas that might help determine why it doesn't work??? [sig][/sig]
 
The question is: why you think that it's intended to work?
The question is: in what book you read this? [sig][/sig]
 
Nick,

I've changed the code to:

buttonClicked.backgroundimage=&quot;url(images/image2.jpg)&quot;;

and I now get a JavaScript error: &quot;object expected&quot;

The image2.jpg does exist in the images directory. Do I have to &quot;preload&quot; it somehow to the browser? Is there a way to do that? Thanks. [sig][/sig]
 
Chris,
I've tried to get this to work, but failed too. I don't get errors, and if I use an alert box to show the backgroundimage, I can see that the value has changed. However, the button still shows the old image.
Can you change to using image objects? then you could just change the src, like in a rollover script.
[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top