Link to home
Start Free TrialLog in
Avatar of jpschreibman
jpschreibman

asked on

Simple javascript: why won't it work cross-browser?

I am trying to use Javascript for a series of menu buttons. When clicked, I want to enter text into a hidden field, and change the border around the clicked icon. My code works fine in Firefox, but not in other browsers. Please advise.


Sample link:
 
<a href="javascript:setButton4();" onClick="javascript:document.forms['search'].cat.value='Toys';" onMouseUp="setButton4();">
 
The javascript functions:
 
function setButton1()  {
	document.button1.style.borderWidth="5"
	document.button2.style.borderWidth="1"
	document.button3.style.borderWidth="1"	
	document.button4.style.borderWidth="1"	
	document.button5.style.borderWidth="1"	
	document.button6.style.borderWidth="1"	
	document.button7.style.borderWidth="1"		
}
function setButton2()  {
	document.button1.style.borderWidth="1"
	document.button2.style.borderWidth="5"
	document.button3.style.borderWidth="1"	
	document.button4.style.borderWidth="1"	
	document.button5.style.borderWidth="1"	
	document.button6.style.borderWidth="1"	
	document.button7.style.borderWidth="1"	
}
function setButton3()  {
	document.button1.style.borderWidth="1"
	document.button2.style.borderWidth="1"
	document.button3.style.borderWidth="5"	
	document.button4.style.borderWidth="1"	
	document.button5.style.borderWidth="1"	
	document.button6.style.borderWidth="1"	
	document.button7.style.borderWidth="1"	
}
function setButton4()  {
	document.button1.style.borderWidth="1"
	document.button2.style.borderWidth="1"
	document.button3.style.borderWidth="1"	
	document.button4.style.borderWidth="5"	
	document.button5.style.borderWidth="1"	
	document.button6.style.borderWidth="1"	
	document.button7.style.borderWidth="1"	
}
function setButton5()  {
	document.button1.style.borderWidth="1"
	document.button2.style.borderWidth="1"
	document.button3.style.borderWidth="1"	
	document.button4.style.borderWidth="1"	
	document.button5.style.borderWidth="5"	
	document.button6.style.borderWidth="1"	
	document.button7.style.borderWidth="1"	
}
function setButton6()  {
	document.button1.style.borderWidth="1"
	document.button2.style.borderWidth="1"
	document.button3.style.borderWidth="1"	
	document.button4.style.borderWidth="1"	
	document.button5.style.borderWidth="1"	
	document.button6.style.borderWidth="5"	
	document.button7.style.borderWidth="1"	
}
function setButton7()  {
	document.button1.style.borderWidth="1"
	document.button2.style.borderWidth="1"
	document.button3.style.borderWidth="1"	
	document.button4.style.borderWidth="1"	
	document.button5.style.borderWidth="1"	
	document.button6.style.borderWidth="1"	
	document.button7.style.borderWidth="5"	
}

Open in new window

Avatar of silemone
silemone
Flag of United States of America image

it may be that  other styles are overriding

if this doesn't work, you could check which browser is being used and based upon that set the borderwidth accordingly where it shows up identical all browsers...
ASKER CERTIFIED SOLUTION
Avatar of quincydude
quincydude
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jpschreibman
jpschreibman

ASKER

No other styles are overriding. It simply is not working in IE.

Thanks for trying.

The HTML is attached below:

	<fieldset>
	<legend>Find More Presents!</legend>
			<form name="search" action="./?page=users_home&act=MORE#look" method="post">
	<table>
	<tr>		
		<td><a href="javascript:setButton4();" onClick="javascript:document.forms['search'].cat.value='Toys';" onMouseUp="setButton4();javascript:document.forms['search'].keyword.value='What type of toys are you looking for?';"><img id="button4" width="85" src="./theme/images/icon_toys.png"  border="5" ></a></td>		
		<td><a href="javascript:setButton5();" onClick="javascript:document.forms['search'].cat.value='VideoGames';javascript:document.forms['search'].keyword.value='What type of video games are you looking for?';" onMouseUp="setButton5();"><img id="button5" width="85" src="./theme/images/icon_games.png"  border="1" ></a></td>			
		<td><a href="#" onClick="javascript:document.forms['search'].cat.value='Books';javascript:document.forms['search'].keyword.value='What type of book are you looking for?';" onMouseUp="setButton1();"><img id="button1" width="85" src="./theme/images/icon_books.png"  border="1" ></a></td>
 
		<td><a href="#" onClick="javascript:document.forms['search'].cat.value='DVD';javascript:document.forms['search'].keyword.value='What type of movie or DVD are you looking for?';" onMouseUp="setButton2();"><img id="button2" width="85" src="./theme/images/icon_movies.png"  border="1" ></a></td>
		<td><a href="#" onClick="javascript:document.forms['search'].cat.value='Music';javascript:document.forms['search'].keyword.value='What type of music are you looking for?';" onMouseUp="setButton3();"><img id="button3" width="85" src="./theme/images/icon_music.png"  border="1" ></a></td>		
		<td><a href="#" onClick="javascript:document.forms['search'].cat.value='Apparel';javascript:document.forms['search'].keyword.value='What type of clothes are you looking for?';" onMouseUp="setButton6();"><img id="button6" width="85" src="./theme/images/icon_clothes.png"  border="1" ></a></td>				
		<td><a href="#" onClick="javascript:document.forms['search'].cat.value='Tools';javascript:document.forms['search'].keyword.value='What type of tools are you looking for?';" onMouseUp="setButton7();"><img id="button7" width="85" src="./theme/images/icon_tools.png"  border="1" ></a></td>				
		<td><a href="#" onClick="javascript:document.forms['search'].cat.value='Electronics';javascript:document.forms['search'].keyword.value='What type of electronics are you looking for?';" onMouseUp="setButton8();"><img id="button8" width="85" src="./theme/images/icon_electronics.png"  border="1" ></a></td>				
	<tr><td colspan="10" style="padding:10px;" bgcolor="#000033"><font color="#ffffff"><b>Search for:</b></font> <input type="text" size="45" name="keyword" value=""> <input class="submit" type="submit" value="go!"></td></tr>
	</table>
	<input type="hidden" name="cat" id="cat" value="Toys">
	<p>Want to browse the regular Amazon.com site? <a class="gen_link" href="http://www.amazon.com/?&tag=mychristma077-20&camp=211173&creative=374757&linkCode=ur1&adid=0MYJDPQBZ3ZBWY3TTZ64&" target="_blank">Click here!</a></p>
 
	</fieldset>
	</form>

Open in new window

Do not use
document.button7.style.borderWidth

try to change to

document.getElementById("button7").style.borderWidth