Reputation: 49384
I have 3 input boxes in my page.
What I need to do is Onchange add the values of Input box A and Input Box B with a comma separating the two values.
For example:
Input A = 'MyValueA'
Input B = 'MyValueB'
Result = 'MyValueA , MyValueB'
Upvotes: 1
Views: 1518
Reputation: 8154
This will allow infinite textboxes
HTML
<input class="valuegroup" id="inputa" />
<input class="valuegroup" id="inputb" />
<input class="output" id="inputz" />
JS
$(function() {
$('.valuegroup').on('change keyup', function() {
var myVal, newVal = $.makeArray($('.valuegroup').map(function(){
if (myVal = $(this).val()) {
return(myVal);
}
})).join(', ');
$('.output').val(newVal);
});
});
Upvotes: 2
Reputation: 10372
$('#inputa, #inputb').change(function (e) {
var result = $('#inputa').val() + ", " + $('#inputb').val();
$('#inputc').val(result);
});
Upvotes: 4
Reputation: 3742
$("#input1, #input2").bind('change', function(){
$("#input3").val($("#input1").val() + ',' + $("#input2").val());
});
Upvotes: 3