Ronald Ronald - 16 days ago 7
jQuery Question

jQuery: Update a certain textbox on if DatePicker UI is changed

I have this problem, a textbox is assigned to get the value of the datepicker. I have no problems doing it initially (meaning at first with no changes on the datepicker) since there's a button to be clicked to produce the hidden textbox. But the problem arises when the value of the datepicker is changed (after the textbox is generated). Here's the sample:

Datepicker:

<input type='text' name='devd' id="devd_1" class='pickdate' size='10' />


Hidden Textbox:

<input type='hidden' name='devd_box' id='devd_box_1'/>


The button that I mentioned should only be used once. So my problem now is how to populate the hidden textbox if the value of the datepicker has changed.

You may notice the last number of the ID, that is their common reference so that it can update the right box since it has multiple datepickers/boxes.

Thanks for all the help!

P.S: The last number after the IDs are dynamically populated thus I can't just hardcode the ID of the datepicker.

Actual solution for those who need it:



$('.pickdate').on('change', function (ev) {
var string_id = this.id;
var lastnum = string_id[string_id.length -1];
$('#devd_box_' + lastnum).val(this.value);
});

Answer

Simply look for the onChange event.

$('#devd_1').on('change', function (ev) {
    $('#devd_box_1').val('Your text here');
});

This will change the text on the hidden field whenever there's a change made on the datepicker field.

Regarding the dynamic id part - Make a javascript function for it and call it to get the actual id.

Note: Please refer the question for the actual solution.

Comments