Reputation: 155
In my form, I have 2 textbox (txtDate, txtTime), 1 hidden textbox (txtDateTime) and Save button. I want value of txtDateTime = txtDate + txtTime and it will automatically change value if user change at txtDate or txtTime.
How can I achieve this ? if you know, pls suggest me. Thanks
Upvotes: 0
Views: 1556
Reputation: 382666
You can use onchange
event like this:
var ttime = document.getElementById('txtTime');
var tdate = document.getElementById('txtDate');
var tdt = document.getElementById('txtDateTime');
ttime.onchange = function(){
tdt.value = tdate.value + ttime.value;
};
tdate.onchange = function(){
tdt.value = tdate.value + ttime.value;
};
Make sure to assign id
attribute to your text boxes eg txtTime
, txtDate
and txtDateTime
Upvotes: 1
Reputation: 13661
Use onchange
<input type='text' onchange='change()' />
function change() {
//code
}
Upvotes: 0