What is the textbox enter event in jquery

174
Views
3
Answers

Hi,
I have datepicker on one of my view in my mvc3 application.
What i want to do is i want to apply some logic when the focus is lost from that textbox.
I want to calculate age and show in other textbox when the user selects a certain date.
Im using blur event but its not working

$("#Date_Of_Birth").blur(function () {});

Suggest how to do this.

edit | flag
Ehtesham Siddiqui
Asked on: Sep 14, 2012 at 2:36PM

3 Answers

158
-1
158

Try Mouse out function

$('#Date_Of_Birth').mouseout(function() {
     
var date= $('#datepicker').val();
   
//Calculate your logic

 
}

If this dosent work put the date picker with in a div> tag and

$('#Divdatepicker').mouseout(function() {
         
var date= $('#datepicker').val();
   
if(date) //validate if some date  is selected
   
{
       
//Calculate your logic
   
}

     
}
edit | flag
Gokul A
Answered on: Sep 14, 2012 at 7:48PM
159
-1
159

If you want to capture the change event of the textbox and not the datepicker then you can use onchange event

You can also wrap the function inside a document ready function.

$(document).ready(function() {
    $
("#textboxdate").change(function() {
       
var date= $('#datepicker').val();
   
});
});

You can use Onfocusout function also

 $("#textboxdate").focusout(function() {
//do logic here

});
edit | flag
Gokul A
Answered on: Sep 14, 2012 at 7:58PM
160
2
160

Hi,
Gokul A.thanks for the reply but i wasnt searching for the change event of TextBox rather the change event of the date.
Below is what my requirement was in case someone need this.
$("myDate").datepicker({
changeYear:true,
changeMonth:true,
onSelect:my_Age_Calculator
});
my_Age_Calculator is my function in jquery that calculates the age.

edit | flag
Ehtesham Siddiqui
Answered on: Sep 15, 2012 at 4:40PM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags