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

Button Script

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi!<br>
<br>
I wrote a script that will change a button on a mouseover, a mouseout and on a mousedown. It works very well, however I would like the "button" to change and stay changed when someone clicks on it (mousedown). However I also want the button to change then change back when the mouse travels over it. I can do the second with no problem, but I can't see any way of telling the script to NOT change the button if it is clicked, until another button is clicked.<br>
Here is the code snippet that I am working with<br>
<br>
I set up the images like so:<br>
<br>
image1= new Image();<br>
image1.src = "images/Home1.jpg";<br>
image1on = new Image();<br>
image1on.src = "images/Home2.jpg";<br>
image1clik = new Image();<br>
image1clik.src = "images/Home3.jpg";<br>
<br>
Throw these functions in:<br>
function on(name) {<br>
document[name].src = eval(name + "on.src");<br>
}<br>
function off(name) {<br>
document[name].src = eval(name + ".src");<br>
} <br>
function clik(name) {<br>
document[name].src = eval(name + "clik.src");<br>
}<br>
<br>
Then use the following HTML to display the mess:<br>
<br>
&lt;a href="home.html" target="main"; <br>
onMouseOver="on('image1')"; <br>
onMouseOut="off('image1')"; <br>
OnMouseDown="clik('image1')"&gt;<br>
&lt;img src="images/Home1.jpg" border="0" name="image1" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt; <br>
<br>
If anybody can figure out how to keep the button down (re: image3.jpg) untill another button is clicked, I would REALLY appreciate it. <br>
<br>
TIA<br>
<br>
John Vogel
 
Hi John; try replacing your existing code & html with this, then see if it works.<br>
(hint: I added a variable to keep track of whether the button has been clicked or not; if it has, then I used an if/then clause to cancel the operation of the other rollovers.)<br>
<br>
<br>
image1= new Image();<br>
image1.src = "images/Home1.jpg";<br>
image1on = new Image();<br>
image1on.src = "images/Home2.jpg";<br>
image1clik = new Image();<br>
image1clik.src = "images/Home3.jpg";<br>
<br>
var isit = "if(clicked == y){";<br>
<br>
function on(name)<br>
{<br>
isit<br>
document[name].src = eval(name + "on.src");<br>
}}<br>
<br>
function off(name)<br>
{<br>
isit<br>
document[name].src = eval(name + ".src");<br>
}}<br>
<br>
function clik(name)<br>
{<br>
document[name].src = eval(name + "clik.src");<br>
}<br>
<br>
<br>
&lt;a href="home.html" target="main" onMouseOver="on('image1')" onMouseOut="off('image1')" OnClick="clik('image1'); var clicked=y;"&gt;<br>
&lt;img src="images/Home1.jpg" border="0" name="image1" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt;<br>
<br>
Hope this works for you<br>
<br>
<br>
-Robherc<br>
robherc@netzero.net
 
Thanks alot, Rob. Actually, I goofed. I should have metnioned there would be more than one button. Anyway, you did set me in the right direction, and after much sweat and hair pulling, I managed to morph my script. Now, when someone clicks on one of the buttons, the script turns off the previously pressed button, resets it to normal, then turns on the clicked button.<br>
This script is really getting messy, If I emailed you a copy, would you be willing to look at it, and see if I can do anything to clean it up. It works great, but it is messy... better yet, I could just copy the whole script in another message, and you could copy it and past it, and see how it works...
 
On secnd thought, you can just surf to my IP (204.177.102.35) and just right click on the left frame (where the buttons are) and click view source (at least I know that this works in IE, I killed my Netscape, sorry, I just like IE too much...
 
Here's a new (greatly altered) source code for your nav bar; please let me know if you find any errors in it (or any of the JS...please post error msgs here)<br>
<br>
<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;script language="JavaScript"&gt;<br>
<br>
<br>
var clicked;<br>
var name;<br>
<br>
image1= new Image();<br>
image1.src = "images/Home1.jpg";<br>
image1x= new Image()<br>
image1x.src = "images/Home1.jpg";<br>
image1on = new Image();<br>
image1on.src = "images/Home2.jpg";<br>
image1clik = new Image();<br>
image1clik.src = "images/Home3.jpg";<br>
<br>
<br>
<br>
image2= new Image();<br>
image2.src = "images/About1.jpg";<br>
image2x= new Image();<br>
image2x.src = "images/About1.jpg";<br>
image2on = new Image();<br>
image2on.src = "images/About2.jpg";<br>
image2clik = new Image();<br>
image2clik.src = "images/About3.jpg";<br>
<br>
<br>
<br>
image3= new Image();<br>
image3.src = "images/Location.jpg";<br>
image3x= new Image();<br>
image3x.src = "images/Location.jpg";<br>
image3on = new Image();<br>
image3on.src = "images/Location2.jpg";<br>
image3clik = new Image();<br>
image3clik.src = "images/Location3.jpg";<br>
<br>
<br>
<br>
image4= new Image();<br>
image4.src = "images/Keyp1.jpg";<br>
image4x= new Image();<br>
image4x.src = "images/Keyp1.jpg";<br>
image4on = new Image();<br>
image4on.src = "images/Keyp2.jpg";<br>
image4clik = new Image();<br>
image4clik.src = "images/Keyp3.jpg";<br>
<br>
<br>
<br>
image5= new Image();<br>
image5.src = "images/Client1.jpg";<br>
image5x= new Image();<br>
image5x.src = "images/Client1.jpg";<br>
image5on = new Image();<br>
image5on.src = "images/Client2.jpg";<br>
image5clik = new Image();<br>
image5clik.src = "images/Client3.jpg";<br>
<br>
<br>
<br>
image6= new Image();<br>
image6.src = "images/GB1.jpg";<br>
image6x= new Image();<br>
image6x.src = "images/GB1.jpg";<br>
image6on = new Image();<br>
image6on.src = "images/GB2.jpg";<br>
image6clik = new Image();<br>
image6clik.src = "images/GB3.jpg";<br>
<br>
<br>
<br>
image7= new Image();<br>
image7.src = "images/FB1.jpg";<br>
image7x= new Image();<br>
image7x.src = "images/FB1.jpg";<br>
image7on = new Image();<br>
image7on.src = "images/FB2.jpg";<br>
image7clik = new Image();<br>
image7clik.src = "images/FB3.jpg";<br>
<br>
<br>
function on(number) {<br>
<br>
if(clicked == number){}else{<br>
name = "image"+number<br>
document[name].src = eval(name+"on.src");<br>
}<br>
}<br>
<br>
function off(number) {<br>
if(clicked == number){}else{<br>
name = "image"+number<br>
document[name].src = eval(name + ".src");<br>
}<br>
} <br>
<br>
function clik(name) {<br>
document[name].src = eval(name + "clik.src");<br>
<br>
}<br>
<br>
<br>
&lt;/script&gt;<br>
<br>
&lt;title&gt;&lt;/title&gt;<br>
<br>
&lt;meta name="Microsoft Border" content="tl, default"&gt;&lt;/head&gt;<br>
<br>
&lt;body onLoad="click('image1')" background="backgrnd.gif" alink="White" vlink="Silver" link="Red" text="Navy"&gt;<br>
<br>
&lt;!-- What's all this stuff for??? (nothing that pints to a "file:///" domain will work on anyone else's computer) --&gt;<br>
&lt;p&gt;&lt;a href="tpe.html" target="main"&gt;!&lt;/a&gt;&nbsp; &lt;br&gt;<br>
&lt;a href="file:///C:/Inetpub/ target="main"&gt;&lt;strong&gt;&lt;big&gt;&lt;big&gt;clik<br>
HERE&lt;/big&gt;&lt;/big&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;&lt;/p&gt;<br>
&lt;!-- End questionable data --&gt;<br>
<br>
&lt;a href="home.html" target="main" ; onMouseOver="Thisis=1;on(1)" ; onMouseOut="off(1)" ; OnMouseDown="clicked=1; clik('image1');"&gt;<br>
&lt;img src="images/Home1.jpg" border="0" name="image1" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt;&lt;br&gt;<br>
<br>
&lt;a href="about.html" target="main" ; onMouseOver="Thisis=2;on(2)" ; onMouseOut="off(2)" ; OnMouseDown="clicked=2; clik('image2');"&gt;<br>
&lt;img src="images/About1.jpg" border="0" name="image2" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt;&lt;br&gt;<br>
<br>
&lt;a href="location.html" target="main" ; onMouseOver="Thisis=3;on(3)" ; onMouseOut="off(3)" ; OnMouseDown="clicked=3;clik('image3');"&gt;<br>
&lt;img src="images/Location.jpg" border="0" name="image3" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt;&lt;br&gt;<br>
<br>
&lt;a href="managers.html" target="main" ; onMouseOver="Thisis=4;on(4)" ; onMouseOut="off(4)" ; onMousedown="clicked=4;clik('image4');"&gt;<br>
&lt;img src="images/Keyp1.jpg" border="0" name="image4" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt;&lt;br&gt;<br>
<br>
&lt;a href="logon.html" target="main" ; onMouseOver="Thisis=5;on(5)" ; onMouseOut="off(5)" ; onMousedown="clicked=5;clik('image5');"&gt;<br>
&lt;img src="images/Client1.jpg" border="0" name="image5" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt;&lt;br&gt;<br>
<br>
&lt;a href="register.htm" target="main" ; onMouseOver="Thisis=6;on(6)" ; onMouseOut="off(6)" ; onMousedown="clicked=6;clik('image6');"&gt;<br>
&lt;img src="images/GB1.jpg" border="0" name="image6" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt;&lt;br&gt;<br>
<br>
&lt;a href="feedback.html" target="main" ; onMouseOver="Thisis=7;on(7)" ; onMouseOut="off(7)" ; onMousedown="clicked=7;clik('image7');"&gt;<br>
&lt;img src="images/FB1.jpg" border="0" name="image7" WIDTH="180" HEIGHT="50"&gt;&lt;/a&gt;&lt;br&gt;<br>
<br>
&lt;/body&gt;<br>
&lt;/html&gt;<br>
<br>
<br>
-Robherc<br>
robherc@netzero.net
 
Whoa! How did I miss your reply? Thanks Rob, I am looking at this slightly enhanced version of the script. Appreciate your reply, sorry I missed it! Now... let me check that little box down there, to be notified of response :)<br>
<br>
I will let you know how this works... thanks again!<br>

 
Hmmm... well the script doesn't work at all now.<br>
When you first load the page, it comes up with an error:<br>
Line: 105<br>
Char: 1<br>
Error: Object expected<br>
<br>
line 105 is:<br>
&lt;body onLoad="click('image1')" ... etc<br>
<br>
I'm not sure what the problem is here, but if I just take that onload out the script still doesn't work. The buttons stay clicked until a mouseover. In Other Words the button doesn't UN click itself on a sub sequeent click of another button...<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top