Click here to Skip to main content
15,896,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Friends,

I have written javascript code and it is working fine in IE but it is not working in Mozilla.

Here is the code
JavaScript
function toggle(controlId, imageId) {

var control = document.getElementById(controlId);
var imageControl = document.getElementById(imageId);

if (control.style.display == 'none') {
    control.style.display = 'block';
    imageControl.src = "images/minus.gif";
}
else {
    control.style.display = 'none';
    imageControl.src = "images/plus.gif";
}
return false;
}

Call this as from server site onclick at imagebutton Like as
JavaScript
image.Attributes.Add("Onclick", "javascript:return toggle('" + grd.ClientID + "','" + image.ClientID + "');")


here image is name of imagebutton.

Also can any one how show me how to write this code in js file so that I can call in multiple pages



Thanks in advance
Upniwesh
Posted
Updated 13-Jun-12 22:28pm
v2
Comments
Sergey Alexandrovich Kryukov 14-Jun-12 1:30am    
No, you never call client-side JavaScript from the server side. It only seems so -- to you. :-)
--SA
krumia 14-Jun-12 4:29am    
What you do in server side is irrelevant. Please include the rendered HTML code that is sent to IE/Firefox client. Looking at that, we may be able to help you.

Hi,
Look into your code carefully:
C#
image.Attributes.Add("Onclick", "javascript:return toggle('" + grd.ClientID + "','" + image.ClientID + "');")


It should be like:
C#
image.Attributes.Add("onclick", "javascript:return toggle('" + grd.ClientID + "','" + image.ClientID + "');")
//"o" should be small in onclick function of javascript.

and paste it inside page_Load event..

All the best.
--AK
 
Share this answer
 
v2
Comments
Upniwesh 14-Jun-12 7:50am    
Thanks Amit but it's not working after write the
image.Attributes.Add("onclick", "javascript:return toggle('" + grd.ClientID + "','" + image.ClientID + "');")

//small "o"
Hi,

instead of adding attribute, register javascript block in your page using Register Client Script block[^]

But this should not be the reason for working in IE and not working in Firefox. there must be some other problem. is all your javascript code execute in FF ? check if you have javascript disabled ?

i also found similar problem here[^]

hope this all information may save your time

thanks
-Amit
 
Share this answer
 
Comments
Upniwesh 14-Jun-12 7:53am    
Thanks Amit

But I don't know how to check Javascript disabled ?????
Please give me idea......
AmitGajjar 14-Jun-12 7:55am    
manually : http://kb.mozillazine.org/JavaScript

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900