Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in iterating values using jquery

I have stuck up with an issue of retrieving multiple values from edit text using jquery. I have two dynamic input text box , while retrieving , i can able to get one column of text. How to get both input text box values

<script type="text/javascript">
$(function () {
    $("#btnAdd").bind("click", function () {
        var div = $("<div />");
        div.html(GetDynamicTextBox(""));
        $("#TextBoxContainer").append(div);
    });
    $("#btnGet").bind("click", function () {
        var values = "";
        var values1 = "";
        $("input[name=name]").each(function () {
            values += $(this).val() + "\n";
        });
        alert(values);
    });
    $("body").on("click", ".remove", function () {
        $(this).closest("div").remove();
    });
});
function GetDynamicTextBox(value) {
    return '<input name = "name" type="text" value = "' + value + '" />&nbsp;<input name = "designation" type="text" value = "' + value + '" />&nbsp;' +
            '<input type="button" value="Remove" class="remove" />'
}
</script>
**Output:**

name:Ram name:Tom

**Expected Output:**
name:Ram , deisgnation:SE
name:Tom, Designation:PM
like image 975
Giridharan Avatar asked May 20 '26 09:05

Giridharan


1 Answers

You're only getting values of the name inputs, not the designation inputs.

$("input[name=name]").each(function() {
    values += "Name:" + $(this).val();
    values += ", designation:" + $(this).next().val() + "\n";
});
like image 138
Barmar Avatar answered May 21 '26 22:05

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!