473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Javascript Object Expected error ASP.NET 2.0 OnkeyPress

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="/wEPDwUJMjgzMDgzOTgzD2QWAgIDD2QWAgIBDw9kFgIeCm9uS2V 5UHJlc3MFElZhbGlkYXRlTnVtZXJpYygpO2RkNE+rQ47DvNQ43 x5HqyR5GtSr/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=63 2886338900000000"
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>

Sep 27 '06 #1
3 10725
ja***@cyberpine.com wrote:
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>
<snip>
</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=63 2886338900000000"
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.

Sep 27 '06 #2


ja***@cyberpine.com wrote:
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>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 27 '06 #3
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 Honnen wrote:
ja***@cyberpine.com wrote:
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>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fred Brown | last post by:
Hi, I want to cancel a certain key in JavaScript. To do so, I catch the event in OnKeyPress and cancel the default: <head> .... function f(evt) { var evt = (evt) ? evt : ((window.event) ?...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
3
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
7
by: CharlesA | last post by:
Hi folks, first off, I'm using .Net framework 1.1 with ASP.net and C# I'm trying to do something very simple...but I can't figure it out I have an <asp:button runat="server"> in the test...
16
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the...
12
Plater
by: Plater | last post by:
Well, I'm stuck asking you all, because I cannot find a piece of code that works in multiple browsers. I have the following code that works in google chrome and ie: //Add a keypress watcher to...
3
by: pdeb1234 | last post by:
i am trying to dynamically load the image of a bullet and then manipulate it using a looping function( with setTimeout() and clearTimeout() methods). here's the code>>>> <html> <head> <script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.