-1

How do i log this successfully please. When i print, it prints only the syntax and not the values. I would also want to display it as text.

       $w("#datePicker1").onChange( (onChange, $w) => {
        let chosenDate = new Date($w("#datePicker1").value);
        let date1 =chosenDate.getDate();
          return date1;

              });




 $w("#datePicker2").onChange( (onChange, $w) => {

          let chosenDate = new Date($w("#datePicker2").value);
           let date2 = chosenDate.getDate();
         return date2;


          });


                          //printing everthing instead of values
       console.log($w("#datePicker1").onChange); 
         console.log($w("#datePicker2").onChange);
Cœur
  • 37,241
  • 25
  • 195
  • 267
usmanelvis
  • 11
  • 4
  • 3
    Perhaps you could provide some more context/details? What exact values are you looking for, the function body etc? The function return? It seems that this might be what you are looking for: https://stackoverflow.com/a/3180012/5206857 – john_mc Mar 23 '18 at 19:59

1 Answers1

1

this is because you're printing the function's actual code, as described in Function.prototype.toString().

$('#some_input').onChange function is an event handler and returning the object of the triggered element (see WixCode DatePicker API Docs)

You didn't mentioned what you wish to do with the date value, so I'm guessing that you may be wanted to put it in your database to update a specific item (the current item the dataset points to). Assuming this is what you're trying to do, here is a code to help:

$w("#datePicker1").onChange((event, $w) => {
  let date = event.target.value;
  // maybe do some manipulation here on the saved value
  $('#dataset1').setFieldValue('last_modified_date', date)
});

Hope this could help, Cheers!

Ziv Levy
  • 1,904
  • 2
  • 21
  • 32
  • Yes, i actually want to Call the Function or use its Value eg: 19. To use as a Mathematical equation, all on the browser and not in the DataSet. So i'm not using a database. This is a DatePicker as so far i don't know how to get the value or date chosen, only by using the event handler function. So if you know another way, that would also help, as i'm just trying to get the value and use it in another method or Maths. Thanks – usmanelvis Mar 25 '18 at 09:36
  • @usmanelvis how about keep another variable outside of the handler, lets call it `var date1;` and then upon each change of the date, the `onChage` handler will update `date1 = event.target.value;` – Ziv Levy Mar 25 '18 at 12:13
  • sends an error:TypeError: Cannot read property 'value' of undefined. when Picked. This is the Code: var date1; console.log(date1); $w("#datePicker1").onChange( (onChange, $w) => { date1 = $w("#datePicker1").onChange.target.value; return date1; }); – usmanelvis Mar 25 '18 at 17:48
  • @usmanelvis you mixed some of the things here. This is how your code should be: `$w("#datePicker1").onChange((event, $w) => {date1 =event.target.value; console.log(date1); });` you shall not return anything – Ziv Levy Mar 26 '18 at 07:33