0

I am trying open a calendar with datepicker on button click, and have the date go into the sibling text box when chosen. I need to be able to do this for two different text boxes.

Here is what I have so far.

http://jsfiddle.net/dan_vitch/zEper/

3
  • So you want the date entered into text box one to go into text box two? Commented Dec 1, 2011 at 2:45
  • It depends. It shouldgo into the text box of the corresponding button. Commented Dec 1, 2011 at 2:53
  • Oh right, well yeh you don't need the buttons. I'll update my answer accordingly. Commented Dec 1, 2011 at 3:00

1 Answer 1

2

You need to load the jQuery UI with that jsfiddle. Try the following:

<div>
    <label>Start</label>
    <input type="text" class="datepicker"/>
</div>

<div>
    <label>End</label>
    <input type="text" class="datepicker"/>
</div>

And your JS:

$(".datepicker").datepicker({
    showOn: "button",
    buttonImage: "link to your button here",
    buttonImageOnly: true
});

Things to note: you don't need to add the button, the datepicker will do that for you - you'll need to add a link to a button image. If you don't like this then you could just remove the bottonImage reference.

All of this has been taken from the jQuery datepicker UI documentation here

EDIT: Fixed up closing tags for html elements, fixed in jsfiddle here

Sign up to request clarification or add additional context in comments.

3 Comments

updated base off of your suggestion, but still not working jsfiddle.net/dan_vitch/zEper/3
+1 for using buttons like he asked, I should read the question better!
Might want to fix up the closing tags in your example though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.