Click here to Skip to main content
13,199,318 members (64,156 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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,
Posted 3-Mar-11 1:08am
Rate this: bad
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.

Doing this would introduce the client side event of text change.


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.
SAKryukov 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.
Sandeep Mewara 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 3-Mar-11 21:29pm
Of course you can add event as the argument. Consider this:

<script type="text/javascript"><!--
function eventHandler(event) {

<input type="text" önchange="event.value=1213; eventHandler(event)" />


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.

Sandeep Mewara 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 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.
Sandeep Mewara 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 3-Mar-11 23:08pm
Every beginner deserve a chance to feel like a master :-)
Sandeep Mewara 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 4-Mar-11 1:06am
xibit89 7-Mar-14 6:40am
Thanks Sandeep Mewara it Worked perfect for me..
Sandeep Mewara 7-Mar-14 7:31am
Great to know!
Rate this: bad
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>
Sandeep Mewara 3-Mar-11 9:39am
OP would get confused. ASP Textbox does not expose the client side onchange via designer! :)
Rate this: bad
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"
honey4bee 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171020.1 | Last Updated 3 Mar 2011
Copyright © CodeProject, 1999-2017
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