javascript not firing

B

bill yeager

I tried placing the following logic in my page_load event
to handle the client-side jhavascript needed to add the
first 2 textboxes to the total:

<code>
txtMileageBeginning.Attributes.Add("onChange", "ChkMileage
(document.getElementById('" &
txtMileageBeginning.ClientID & "'),
document.getElementById('" & txtEnding.ClientID & "'),
document.getElementById('" & txtTotal.ClientID & "');")

txtEnding.Attributes.Add("onChange", "ChkMileage
(document.getElementById('" &
txtMileageBeginning.ClientID & "'),
document.getElementById('" & txtEnding.ClientID & "'),
document.getElementById('" & txtTotal.ClientID & "');")

Dim sbChkMileage As New StringBuilder
sbChkMileage.Append("<SCRIPT
language='javascript'>")
sbChkMileage.Append("function ChkMileage
(objTextBox1, objTextBox2, objTextBox3) { ")
sbChkMileage.Append("if(objTextBox1.value.length
0 && objTextBox2.value.length > 0 && document.")
sbChkMileage.Append("getElementById
(objTextBox3).value == objTextBox1.value +
objTextBox2.value)}")
sbChkMileage.Append("</SCRIPT>")
RegisterStartupScript
("PageStartupScriptChkMileage", sbChkMileage.ToString)
sbChkMileage = Nothing
</code>

When I'm debugging and view the source code, I get the
following in the View Source:
<code>
onChange="ChkMileage(document.getElementById
('txtMileageBeginning'), document.getElementById
('txtEnding'), document.getElementById('txtTotal');



<SCRIPT language='javascript'>function ChkMileage
(objTextBox1, objTextBox2, objTextBox3) { if
(objTextBox1.value.length > 0 && objTextBox2.value.length
0 && document.getElementById(objTextBox3).value ==
objTextBox1.value + objTextBox2.value)}</SCRIPT>
</code>

While also debugging, there was no "running document"???

What am I doing wrong, because the javascript is not
firing after I place values in the first two textboxes???
 
N

Natty Gur

HI,

from MSDN : "This event is fired when the contents are committed and not
while the value is changing. For example, on a text box, <b> this event
is not fired while the user is typing, but rather when the user commits
the change by leaving the text box that has focus. </b> In addition,
this event is executed before the code specified by onblur when the
control is also losing the focus."

HTH

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
H

Hans Kesting

bill yeager said:
I tried placing the following logic in my page_load event
to handle the client-side jhavascript needed to add the
first 2 textboxes to the total:

<code>
txtMileageBeginning.Attributes.Add("onChange", "ChkMileage
(document.getElementById('" &
txtMileageBeginning.ClientID & "'),
document.getElementById('" & txtEnding.ClientID & "'),
document.getElementById('" & txtTotal.ClientID & "');")

"ClientID" might not be enough: try UniqueID.Replace(":", "$")
The controls in html have longer names than within your code!

Hans Kesting
 

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

Top