Javascript Object Expected error ASP.NET 2.0 OnkeyPress

J

jason

I have a very simple asp.net 2.0 page with one textbox that onkeyPress
is suppose to do some check of what was typed. Below is the source
showing the javascript function is available. The minute I strike a key
I get the error. Anybody know why?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script language="javascript" type="text/javascript ">
function ValidateNumeric()
{
var keyCode = window.event.keyCode;
if (keyCode > 57 || keyCode < 48)
window.event.returnValue = false;
}
</script>



<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default3.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJMjgzMDgzOTgzD2QWAgIDD2QWAgIBDw9kFgIeCm9uS2V5UHJlc3MFElZhbGlkYXRlTnVtZXJpYygpO2RkNE+rQ47DvNQ43x5HqyR5GtSr/xo="
/>
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>


<script
src="/firstmaster/WebResource.axd?d=1cOHSBDcUybKo8LLKYn7Sw2&amp;t=632886338900000000"
type="text/javascript"></script>

<div>
<input name="TextBox1" type="text" id="TextBox1"
onKeyPress="ValidateNumeric();" /></div>

<div>

<input type="hidden" name="__SCROLLPOSITIONX" id="__SCROLLPOSITIONX"
value="0" />
<input type="hidden" name="__SCROLLPOSITIONY" id="__SCROLLPOSITIONY"
value="0" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value=""
/>
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT"
value="" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
value="/wEWAgLO+I33BQLs0bLrBlhWg+CjAmuM6TyVJKn2rdkeNUlP" />
</div>

<script type="text/javascript">
<!--

theForm.oldSubmit = theForm.submit;
theForm.submit = WebForm_SaveScrollPositionSubmit;

theForm.oldOnSubmit = theForm.onsubmit;
theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit;
// -->
</script>
</form>
</body>
</html>
 
R

Richard Cornford

I have a very simple asp.net 2.0 page with one textbox that onkeyPress
is suppose to do some check of what was typed. Below is the source
showing the javascript function is available. The minute I strike a key
I get the error. Anybody know why?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script language="javascript" type="text/javascript ">
function ValidateNumeric()
{
var keyCode = window.event.keyCode;

This is an IE formulation, yet IE does not understand XHTML at all.
if (keyCode > 57 || keyCode < 48)
window.event.returnValue = false;

This is an IE formulation, yet IE does not understand XHTML at all.
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

Are you really expecting a SCRIPT element outside of the html element
to be recognised?
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default3.aspx" id="form1">
<div>
</div>

<script type="text/javascript">
<!--

In a document parsed by an XML parser (such as an XHTML document)
comments in PCDAT sections (such as the content of script elements) may
be removed, taking scripts like this one with them.
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>


<script
src="/firstmaster/WebResource.axd?d=1cOHSBDcUybKo8LLKYn7Sw2&amp;t=632886338900000000"
type="text/javascript"></script>

Your culprit may well be in this undisclosed file.
<div>
<input name="TextBox1" type="text" id="TextBox1"
onKeyPress="ValidateNumeric();" /></div>
<snip>

Apart from the obvious insanity of writing a document in the guise of
XHTML and then doing it so badly, and scripting it, as to require that
it only ever be interpreted as HTML and by a very tolerant tag soup
parser at that, there is nothing here to explain errors when keys are
pressed.

Richard.
 
M

Martin Honnen

I have a very simple asp.net 2.0 page with one textbox that onkeyPress
is suppose to do some check of what was typed. Below is the source
showing the javascript function is available. The minute I strike a key
I get the error. Anybody know why?

Which browser gives exactly which error?

function ValidateNumeric()
{
var keyCode = window.event.keyCode;
if (keyCode > 57 || keyCode < 48)
window.event.returnValue = false;
}
<input name="TextBox1" type="text" id="TextBox1"
onKeyPress="ValidateNumeric();" />

<input type="text" onkeypress="return ValidateNumeric(event);" ... />


<script type="text/javascript">
//<![CDATA[
function ValidateNumeric (evt) {
var charCode = evt.charCode ? evt.charCode : evt.keyCode;
return charCode > 47 && charCode < 58;
}
//]]>
</script>
 
J

jason

ie 6.0

I figured out what it was and drove me crazy

The space after javascript...

<script language="javascript" type="text/javascript ">

wow. thanks.



Martin said:
I have a very simple asp.net 2.0 page with one textbox that onkeyPress
is suppose to do some check of what was typed. Below is the source
showing the javascript function is available. The minute I strike a key
I get the error. Anybody know why?

Which browser gives exactly which error?

function ValidateNumeric()
{
var keyCode = window.event.keyCode;
if (keyCode > 57 || keyCode < 48)
window.event.returnValue = false;
}
<input name="TextBox1" type="text" id="TextBox1"
onKeyPress="ValidateNumeric();" />

<input type="text" onkeypress="return ValidateNumeric(event);" ... />


<script type="text/javascript">
//<![CDATA[
function ValidateNumeric (evt) {
var charCode = evt.charCode ? evt.charCode : evt.keyCode;
return charCode > 47 && charCode < 58;
}
//]]>
</script>
 

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

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top