errors when running it with Netscape or Firefox.

C

Chris

Hi,

I have no problem when running this asp.net application with IE.
But with Netscape 8 and Firefox, i get two javascript
errors:

1) Error: document.getElementById("hiddenfield1") has no properties
2) Error: myfinc is not defined

the aspx file:
-----------
<form id="form1" runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" />
</form>
......
<input runat="server" id="Submit1" type="button" onclick="myfunc()"/>

<script language="javascript" type="text/javascript">
var hid=document.getElementById("hiddenfield1").value
.....

function myfunc()
{
alert("ok")
}
.....
</script>

the code-behind:
---------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
.....
HiddenField4.Value = "1"
.....


Any help is welcome.
Chris
 
R

Randy Webb

Chris said the following on 11/4/2007 4:45 PM:

[follow-up set to microsoft.public.scripting.jscript]
Hi,

I have no problem when running this asp.net application with IE.
But with Netscape 8 and Firefox, i get two javascript
errors:

1) Error: document.getElementById("hiddenfield1") has no properties

That is what happens when you try to access something before the
document has finished loading. The results you get are anybodys guess.
2) Error: myfinc is not defined

I hope that error is myfunc is not defined. If it is myfinc, then
something else is wrong.
the aspx file:

What happens on the server is irrelevant other than it creates what the
browser gets. Post the resulting client side code instead.
 
B

bruce barker

unlike IE, most browsers treat the id as case sensitive following the
w3c spec. (IE has a few bugs in this area especially between is and names).

-- bruce (sqlwork.com)
 
C

Chris

thanks

bruce barker said:
unlike IE, most browsers treat the id as case sensitive following the w3c
spec. (IE has a few bugs in this area especially between is and names).

-- bruce (sqlwork.com)
 
J

Joe Fawcett

Chris said:
Alkso remember that the server-side id of a control is not necessarily the
same as the client-side one. This happens when the control is inside another
control implementing INamingContainer. One way to improve the script is to
use the control's ClientID. You can sometimes just put this in the page
between your script block:
var sTargetId = "<% HiddenField1.ClientId %>";
and then use sTargetId later or you can construct the script on the server
and inject it into the page using the ScriptManager.
There is an article in MSDN which deals with these issues
http://msdn.microsoft.com/msdnmag/issues/07/11/CuttingEdge/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top