Server resonse appeend in textbox dynamically

this below the server response I am getting, I want to append this value in the textbox, I have only input name like this in [] I know if there are input unique input id name OR class name, but in my case my server response is not constant and based on that response I want to generate the textbox and append each value in textbox.

Please help

<input type="text" name="name[]"/>
<input type="text" name="name[]"/>

<input type="text" name="dob[]"/>
<input type="text" name="dob[]"/>

Console Response

1. data2: [{name: "1", dob: "11-11-1111"},…]

  1. 0: {name: "1", dob: "11-11-1111"}
  2. 1: {name: "2", dob: "22-22-2222"}

Expected Output

$("input[name='name[]']").val(data.data2[0].name);
$("input[name='dob[]']").val(data.data2[0].dob);

$("input[name='name[]']").val(data.data2[1].name);
$("input[name='dob[]']").val(data.data2[1].dob);

So what part are you having trouble with? I see you are accessing the data correctly from the response. Are you just looking for how to generate the textbox on the fly and then set it? If so, check out createElement with the value of input and then setting its type attribute to text. From there you can set the value.

let textboxExample = document.createElement('input');
textboxExample.setAttribute('type', 'text');

// Now use textboxExample to set its value and append it to the page

See more in example below…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.