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

Posted on 2008-11-10
Last Modified: 2013-12-08
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()  {"5""1""1""1""1""1""1"		


function setButton2()  {"1""5""1""1""1""1""1"	


function setButton3()  {"1""1""5""1""1""1""1"	


function setButton4()  {"1""1""1""5""1""1""1"	


function setButton5()  {"1""1""1""1""5""1""1"	


function setButton6()  {"1""1""1""1""1""5""1"	


function setButton7()  {"1""1""1""1""1""1""5"	


Open in new window

Question by:jpschreibman
    LVL 21

    Expert Comment

    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...
    LVL 15

    Accepted Solution

    Cannot test your code without the html, but you can merge this
    onClick="javascript:document.forms['search'].cat.value='Toys';" onMouseUp="setButton4();"
    to just

    Author Comment

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

    Thanks for trying.

    The HTML is attached below:

    	<legend>Find More Presents!</legend>
    			<form name="search" action="./?page=users_home&act=MORE#look" method="post">
    		<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>
    	<input type="hidden" name="cat" id="cat" value="Toys">
    	<p>Want to browse the regular site? <a class="gen_link" href="" target="_blank">Click here!</a></p>

    Open in new window

    LVL 15

    Expert Comment

    Do not use

    try to change to


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Now-a-days, indirectly, postal services have been replaced by email services. Yes, whenever we hear the word "email" a lot of people only think of gmail. Some people still think that email and gmail are one and the same thing :-). Let's see some …
    Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
    This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
    How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now