How to set a TextBox value when another TextBox value is changed

grayfield

I have two textboxes with datepicker like this.

<script type="text/javascript">
    $(function () {
        $('#value_date').datetimepicker({ format: 'MM/DD/YYYY' });
        $('#run_date').datetimepicker({ format: 'MM/DD/YYYY hh:mm a' });
    });

</script>

<div class='input-group date' id='value_date'>
    <input type="text" id="txtValueDate" class="form-control" runat="server" placeholder="Value Date"/>
    <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
    </span>
 </div>

<div class='input-group date' id='run_date'>
    <input type="text" id="txtRunDate" class="form-control" runat="server" placeholder="Run Date" />
    <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
    </span>
 </div>

Then, when value_date's value changed, (e.g. 03/31/2016), the run_date is automatically set to value_date's yesterday (03/30/2016) as the default run_date, but still can be changed by datetimepicker. How I do this?

Iakovos Exadaktylos

You should use the change event of the input box. Also you need to correct the id selectors you use. Finally, I sugest you include the momentjs library (link) to calculate and format the display of the previous day:

$('#txtValueDate').change(function(){   
  $('#txtRunDate').val(moment($(this).val()).subtract(1, 'days').format('MM/DD/YYYY'));
    });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to automatically set value of textbox according to value of another textbox

Set textbox value when another change in a listview

how to set a textbox readonly in table in jdeveleper based on another textbox value?

how to set textbox value in jquery

How to set javascript variable value from selected textboxes to another textbox

How to copy textbox value to another textbox when checkbox is checked with while loop?

How to pass textbox value from a page into a textbox in another page?

How to select textbox value and move to the another textbox using selenium python

how can i get sum of checkbox value and textbox value in another textbox when checkbox is checked or if checkbox unchecked remove the value

asp.net textbox changed event not fired when textbox value is changed in jquery code

How to assign textbox value to another class in wpf

How to Display value of textbox in label in another form?

how to get the value of category and then displays it in another textbox

Is there a way to listen to textbox when its value is changed programmatically

How to set a TextBox value with a button click in ReactiveUI

how to set TextBox value as textfile name

How to set a default value for reporting services textbox?

Adding numeric value from textbox into another textbox

How to show/hide div when both the textbox and select box value changed?

How to get Previous textbox value when click on <a>?

What is the best way to update a textbox forecolour when the value within the textbox has been changed?

Textbox is reference to another Textbox, need to return the value of whats in the second textbox

Set input textbox value from another model in angularjs

set the value in textbox appears automatically

How can I use a textbox value to set a value on a radiobutton

How to determine the value of a textbox based on the previous textbox?

How to set time value from one textbox to another wicked time picker?

C# ComboBox and TextBox dynamic value - How can I access a TextBox value from another function or event?

Copying the value of one textbox to another textbox does not work if Visible property is set to false