Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
Hai,
I have two text boxes named txtDOB (Date Of Birth), and txtDOJ (Date of Join)
i have to compare both text boxes DOJ is not greater than DOB..
For this i wrote a java script function, my problem is how to cal that
java script function in txtDoJ's "OnTextChanged Event ",
 
If u know help me..
 
Thanks and Regards,
Honey.
Posted 3-Mar-11 2:08am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

For this i wrote a java script function, my problem is how to cal that
java script function in txtDoJ's "OnTextChanged Event ",

 
You need to add an attribute of client side onchange from server side.
Try:
txtDOJ.Attributes.Add("onchange","javascript:MyJSMethodWhereINeedToChange()");
 
Doing this would introduce the client side event of text change.
 
OR
 
Alternatively, you can use the HTML input control. In that, directly onchange in html designer would trigger the JS event. In order to trigger server textchange event, you would need to use onserverchange event.
  Permalink  
Comments
SAKryukov at 3-Mar-11 12:45pm
   
That's good, but in more general case you also need to pass "event" to the Javascript function.
My 4 this time.
--SA
Sandeep Mewara at 3-Mar-11 13:36pm
   
Event as in? I didn't get that. In general, above works for almost all the cases. At times, one might need to pass on the control's id at max. What else?
SAKryukov at 3-Mar-11 21:29pm
   
Of course you can add event as the argument. Consider this:
 
<html>
<head>
<script type="text/javascript"><!--
function eventHandler(event) {
alert(event.type);
alert(event.value);
}
--></script>
</head>
<body">
 
<input type="text" önchange="event.value=1213; eventHandler(event)" />
 
</body>
</html>
 
In this code, even will be fired when you type something and hit enter; the handler will alert type "change" and than "1213". This is very useful. For some other events like "OnKeyPress" this is critically important, without event information you cannot filter out keystroke to make input control typing just digits, or something like that.
 
--SA
Sandeep Mewara at 3-Mar-11 22:28pm
   
Yep, we can. My point was, why to if we can do without it in most of the case. Out here in OP cases for sure.
 
:)
SAKryukov at 3-Mar-11 22:37pm
   
Well, yes, it may or may not be needed, depending on event type as well. Still, pretty useful, because you can use the same handler code for different controls (and even different event types), still having some data to tell one case from another. That was my point.
--SA
Sandeep Mewara at 3-Mar-11 22:46pm
   
Ok. I agree on that. I was just a little confused on why would we need it here. :)
 
(And while suggesting a beginner, if I add on events too, I am sure I will be pinged back, with what & why) :P
SAKryukov at 3-Mar-11 23:08pm
   
Every beginner deserve a chance to feel like a master :-)
--SA
Sandeep Mewara at 4-Mar-11 0:09am
   
I have yet to start signature lines in my signature. But, whenever I do, this would be the first. :)
 
(Requested, Copied, Will be published - obviously with your name)
SAKryukov at 4-Mar-11 1:06am
   
:-)
xibit89 at 7-Mar-14 6:40am
   
Thanks Sandeep Mewara it Worked perfect for me..
Sandeep Mewara at 7-Mar-14 7:31am
   
Great to know!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Call your javascript on onchange event.
<asp:TextBox ID="txtDOJ" runat="server" onchange="javascript:alert('test');"></asp:TextBox>
  Permalink  
Comments
Sandeep Mewara at 3-Mar-11 9:39am
   
OP would get confused. ASP Textbox does not expose the client side onchange via designer! :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If you want to compare two text boxes having date time values, I would recommend you should use a compare validator with Type="Date"
  Permalink  
Comments
honey4bee at 4-Mar-11 4:20am
   
K accepted.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 3 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100