1

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'
0

3 Answers 3

4
$('#inputa, #inputb').change(function (e) {
  var result = $('#inputa').val() + ", " + $('#inputb').val();
  $('#inputc').val(result);
});
Sign up to request clarification or add additional context in comments.

Comments

3
$("#input1, #input2").bind('change', function(){
      $("#input3").val($("#input1").val() + ',' + $("#input2").val());
});

Comments

2

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);

  });
});​

DEMO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.