DatePicker Getdata store it in link

help, i want to get data from datepicker and the data must be in YYYY-MM-DD format
so i have 2 datepicker, and 1 textbox

i want to open a new link with this url
URL: Check in Date(YYYY-MM-DD) &DD= Your Check out Date(YYYY-MM-DD) &A= Adult

for e.g

so the datepicker1(checkin) data will be shown to the checkindate
and datepicker 2(checkout) data will be shown to the checkoutdate
the format should be (YYYY-MM-DD) , please help me with the code,
thank you

See the Datepicker API for information on retrieving dates from the component and the article on Formatting Dates .

well i already ready about the formatting dates, it said about datetext , in my case i didnt use textbox or anything i just use datepicker from wix and want to take the data to the link , also i didnt connect it to any datashet

You get the selected date from the Datepicker using the .value property. Then you can format the date any way that you need.

after i got the value , how to i insert it to button link?
i already try this code and still , my button do nothing on click
export function button6_click(event) {
var adult =$w(‘#Adult’).value;
var datein = $w(“#datePicker1”).value;
var dateout =$w(“#datePicker2”).value;
$w(‘#button6’).link= “htttp://Error”+datein+ “&DD=” +dateout+“&A=”+ adult;
$w(“#button6”).target = “_blank”;

The Button’s .link and the .target properties need to be set before clicking on the Button. You can set them in the page’s onReady() event handler, or in your case the DatePicker’s onChange() event handler would probably make more sense. Something like this:

$w("#datePicker").onChange( (event) => {
    $w('#button6').link= "htttp://" + datein + "&DD=" + dateout + "&A=" + adult;
    $w("#button6").target = "_blank";

but i need to open this link after the click, like you can see , i need to get the data to the link

Remove the click handler you have on #button6 and use this. Make sure #Adult has a default numerical value.

$w.onReady(() =>
$w(‘#Adult, #datePicker1, #datePicker2’).onChange(handleInputChange);
$w(“#button6”).target = “_blank”;

function handleInputChange()
const adultCount = $w(‘#Adult’).value;
const dateIn = $w(“#datePicker1”).value;
const dateOut =$w(“#datePicker2”).value;

const dateInStr = `${dateIn.getFullYear()}-${("0"+(dateIn.getMonth()+1)).slice(-2)}-${("0"+dateIn.getDate()).slice(-2)}`; 
const dateOutStr = `${dateOut.getFullYear()}-${("0"+(dateOut.getMonth()+1)).slice(-2)}-${("0"+dateOut.getDate()).slice(-2)}`; 

$w('#button6').link = `${dateInStr}&DD=${dateOutStr}&A=${adultCount}`; 



Another option is to use in the button6_click() function. This way you can build the link when the button is clicked, and then redirect.

I was going to do that at first but the docs indicate through omission that opening the URL in a new tab isn’t possible. His use of _blank suggested he wanted that.

1 Like

I was just suggesting another way. Also, new tab or current tab is often dependent on the browser and the target property has no effect.

1 Like

Hello Mr.Lee,

Thank you very much, for the help.