tags:

views:

77

answers:

2

I have this code in the view to display datepicker for input type..

Problem Is when I click on the textbox on the UI I can select the date its working fine..

but when I am trying to clear the textbox its not going off its allways showing currect date and time..

Can anybody help me why its i am not able to make clear..

thanks

+3  A: 

I am trying to understand when you want it cleared. This code will clear it whenever the input receives focus:

$("input[id^='exc-flwup-']").focus(function() {
    $(this).val('');
});

You can change focus to click if it should only clear when you click.

patrick dw
Thanks for your responce... when i click on my input box i am getting pop message but when i clear enter date and time from the input box its not even going allways i am getting the previous date which i selected from calendar control>?can you help me out where do i need to put this $('input').val('') in my above code? thanks
kumar
The question I would have is *when* do you want it to clear? In other words, what event should trigger the code that clears the input?
patrick dw
I need to clear the input text field when i dont need.ex: unfortunatly if i slected date but later i thought of removing date field from input text i need to clear the textbox.. thanks
kumar
What I mean is, do you want it to clear when you `click` in the `input` field? Or do you want it to clear when you `mouseover` the `input` field? Or when any sort of `focus` is placed on the `input` field? There needs to be some event beyond you just wanting it clear.
patrick dw
Thanks.. if you see this example..http://jqueryui.com/demos/datepicker/when he click on the input text filed pop up calender apperas and we can select the date from that.. but if i need to clear that he can clear but my case when i am trying to clear always getting previous date defautly in my textbox.
kumar
@kumar - What are you currently doing to clear the field? You say that you are getting the previous date. Ok, so show me the code that is giving you the previous date.
patrick dw
Frist time which ever the date we selected.. after selecting when i am trying to clear its allways showing the todays date with time 00:00 AM please correct me if i am wrong.. thanks for your time
kumar
@kumar - But **what** are you currently doing to try to clear? **What event** lets the `input` know that it is time to clear?
patrick dw
patrick i dont know how to code there to tell that to clear the input. bec i am completely new to this jquery..i was serching to findout but i am not able to.. thanks for your time on this with me..
kumar
@kumar - Do you want it to clear when you click on it? Or when you hover over it?
patrick dw
when i click on it i need to clear patrick,..
kumar
@kumar - ok, if you look at the edit that I did in my answer, it will clear the date whenever the `input` receives focus (like clicking). Please try that and let me know if it works. Paste it below your `datepicker` code.
patrick dw
Yes patrick I did but same thing happening not able to clear the field..patrick please if you can see my code using teamviewer i can provide the ID and passward? thanks
kumar
patrick when i click escape key its working for me.. not event click its not working..
kumar
@kumar - Sure, I'll take a look.
patrick dw
parick how do i need to close with out hitting escape key?
kumar
In Patrick's solution, `id^=exc-flwup-` should probably be `id^=exc-flwup-<%=Model.ExceptionID %>`
jdigital
How to close the popup calender window on click?
kumar
@kumar - You should be able to close the popup by clicking anywhere else on the page.
patrick dw
@jdigital - No, it is using a "starts with" selector. It is the same selector that kumar is using to generate the datepicker.
patrick dw
yes its closing but again the date filed is comming on to the textbox.. only with escape key its working..
kumar
@kumar - Did you try my code example?
patrick dw
patrick after selecting the date when i click on any where on the page its showing the date fyn.. but when i click the date from input textbox and after when i click anywhere on the page its again showing me the date on the input textbox..
kumar
yes i tried patrick..i am able to clear the text filed but pop up window stays there.. when i am trying close that again textbox showing up the date.. :(
kumar
@kumar - Yes, the date will not go away on its own. You need write code and let it know *when* you want it to go away. Did you try my code?
patrick dw
yes i tried your code patrick.. but still showing me the same thing...i appriciate patrick for your time..
kumar
@kumar - Then there is something else wrong. If the code clears it, but it appears again *without* clicking on the datepicker, then something else must be causing that. Can you paste more code in your question?
patrick dw
yes i will paste my entire code patrick.. please see my update..
kumar
@kumar - Please click on this link and tell me if this is what you want: http://jsfiddle.net/yWgpT/
patrick dw
yes patrick i need exactly this.. but you have modifed the input field.. actually when i am display this view i am displaying this input field if database is having for this exception.. or i can edit or update choosing our own date for that exceptions..so that' why i declared <input type="text" id="exc-flwup-<%=Model.ExceptionID %>" name="exc-flwup-<%=Model.ExceptionID %>" value="<%=Model.FollowupDate %>" />
kumar
@kumar - Yes, your server side code shouldn't make a difference unless there is some communication with the server that causes the datepicker to display again. I'm sorry, but I don't know how to help beyond this.
patrick dw
yes i thinking same thing patrick bec its working here which you showed the example but its not working on my system..
kumar
its workin good when i press Escape key on my keyboard..
kumar
@kumar - very strange. Something is triggering the datepicker when you click elsewhere on the page.
patrick dw
patrick that is the code which is there in my question other than that i am not doing anything on this view :)
kumar
@kumar - Instead of your server code, can you post the HTML that gets sent to the client? I can't test your server code. If you do, I will give it a try tomorrow.
patrick dw
sure patrick i ill do that.. thanks for your precious time with me i appriciate your help thank you soo much..
kumar
+1 for patience, Patrick!
jdigital
@jdigital - Thanks. :)
patrick dw
@kumar - Were you going to post your HTML?
patrick dw
patrick I found one thing in this.. in this code.. $("input[id^='exc-flwup-']").datepicker({ duration: '', showTime: true, constrainInput: false, stepMinutes: 30, stepHours: 1, altTimeField: '', time24h: true, minDate: 0 });if I make showTime: false; its working fine but i am not able to set the time there.. thanks for your followup with me.
kumar
+1  A: 

$('#your-input-text-id').val('');

booota