Click here to Skip to main content
15,891,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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:
C#
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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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 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?
Sergey Alexandrovich Kryukov 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 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.

:)
Sergey Alexandrovich Kryukov 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
Call your javascript on onchange event.
<asp:TextBox ID="txtDOJ" runat="server" onchange="javascript:alert('test');"></asp:TextBox>
 
Share this answer
 
Comments
Sandeep Mewara 3-Mar-11 9:39am    
OP would get confused. ASP Textbox does not expose the client side onchange via designer! :)
If you want to compare two text boxes having date time values, I would recommend you should use a compare validator with Type="Date"
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900