Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
copying a WebDatePicker
posted

So, I'm working on a little project, the gist of it is...

I have a website where there is an option to enter information for kids, fairly basic name and birthday. Well I also give them the option to delete a kid. When that happens the "next" kid becomes the previous. For example: If I added 2 kids and later changed my mind to delete kid1, kid2 would become kid1. I do this as I don't want to leave kid sections visible if not needed.

So, I am running into the problem of setting/changing the date of kid 1 to reflect the date of kid 2. Debuggin with visual studio I am able to see the WebDatePicker is fairly complex. That being said, I assumed setting the value would work, but it doesn't - the old value remains.

I've tried other things as well...

var kidBday = document.getElementById("ctl00_AllegMain_Kid" + i + "wrkBirthDate");
var nextKidBday = document.getElementById("ctl00_AllegMain_Kid" + (i + 1) + "wrkBirthDate");

kidBday.attributes[0].value = nextKidBday.attributes[0].value;
kidBday.attributes[0].textContent = nextKidBday.attributes[0].textContent;
kidBday.attributes[0].nodeValue = nextKidBday.attributes[0].nodeValue;


var kidBdayClient = document.getElementById("ctl00_AllegMain_Kid" + i + "wrkBirthDate_clientState");
var nextKidBdayClient = document.getElementById("ctl00_AllegMain_Kid" + (i + 1) + "wrkBirthDate_clientState");

kidBdayClient.value = nextKidBdayClient.value;

kidBdayClient.defaultValue = nextKidBdayClient.defaultValue;
kidBdayClient.attributes[3].nodeValue = nextKidBdayClient.attributes[3].nodeValue;
kidBdayClient.attributes[3].textContent = nextKidBdayClient.attributes[3].textContent;
kidBdayClient.attributes[3].value = nextKidBdayClient.attributes[3].value;


 I've tried all of the above in various stages, 1 at a time, all of them at once and everything in between. I've even tried setting the innerHTML to each other. Which ultimately disables the date picker pop up picker.

Any input would be greatly appreciated. 

Parents
No Data
Reply
  • 10685
    Offline posted

    Hello,

    Thank you for posting in our community!

    If I understand correctly by the provided description, what is required is to pass the date from a control (WebDatePicker, Input or else) to another WebDatePicker control (when deleting an entry in the current implementation). I have created a simple code sample illustrating several possibilities. These include using the following methods get_date(), get_value(), get_text() and the corresponding set_value() and set_text(); Which ones you use will depend on your implementation or preferences.
    I am attaching a runnable code sample to illustrate these and I have used two WebDatePicker controls.
    Please notice I have handled   WebDatePicker2_ValueChanged event and yet, the controls references are not obtained from the sender and the arguments not from eventArgs, so you are not bound to handle this particular event but implement a similar logic in a custom function.

    function WebDatePicker2_ValueChanged(sender, eventArgs)

    {
       
    var dp = $find("<%=WebDatePicker1.ClientID%>");
        var dp2 = $find("<%=WebDatePicker2.ClientID%>");

        //alternatively you could get the WDP references using
       
    //var dp = ig_controls.WebDatePicker1;
        //var dp2 = ig_controls.WebDatePicker2;

        if (!dp || !dp2) {
           
    return;
        }        

        //Option one using/passing date
       
    //to set value of datepicker, you need Date object, so you may try
       
    //var theNewDate = dp2.get_date();
        //dp.set_value(theNewDate);   //or directly pass the value from dp2 to dp --> dp.set_value(dp2.get_date()); Or even    dp.set_value(dp2.get_value())

        //Option two using/passing text using set_text(dateText),
       
    //however, format of dateText should match with the datePicker format.
       
    //var dp = ig_controls.WebDatePicker1;
       
    //var dp2 = ig_controls.WebDatePicker2;
       
    //var theNewDateAsText = dp2.get_text();
       
    //dp.set_text(theNewDateAsText);
    }

    Please let me know in case you have any more questions or concerns regarding this matter!

    WDP_setValue_setText.zip
Children
No Data