I two groups and every group have two textboxes. Now I want get values of all text boxes and display in third in this format: 2 apple, 3 watermelon
I will explain better with example:
I want this:
Group 1
Textbox1 = 2
Textbox2 = apple
Group 2
Textbox1 = 3
Textbox2 = watermelon
and third should looks like this:
Textbox3 = 2 apple, 3 watermelon
This is simple html code:
<input type="text" name="text1"><br />
<input type="text" name="text2"><br />
<br/><br/>
<input type="text" name="text1"><br />
<input type="text" name="text2"><br />
<input type="submit" value="Add" id="getValue">
<br /><br />
<input type="text" id="text3" />
I have tried to do like this, and works only with textbox 1, I don't know how to add second textbox in javascript.
$(function () {
$('#getValue').click(function() {
$('#text3').val('');
var values = [];
$('input[name="text1"]').each(function(i, elem) {
$("#text3").val(($("#text3").val() + ', ' + $(elem).val()).replace(/^, /, ''));
});
});
});