I have dynamically added textbox in asp.net web form page using javascript as following
<script type="text/javascript">
var i = "Placehoder";
$("#partAdder").click(function () {
newPart =
'<div class="row" id="row">' +
'<div class="col-xl-2">' +
'<div class="form-group">' +
'<input type="text" runat="server" class="form-control form-control-sm" placeholder='+i+' />' +
'</div>' +
'</div>' +
'</div>';
$('#newistrpart').append(newPart);
});
How to pass the i value to the script "using that script i gent +i+ instead of the value"
2
Answers
I’m not sure but if I understand your JS code, you forgot to put " on your placeholder like that
'<input type="text" runat="server" class="form-control form-control-sm" placeholder="'+i+'" />'
you can use string interpolation
${i} syntax is used to include the value of the i variable within the string. The backticks (`) are used to enclose the string, which allows for string interpolation.
backtick shortcut on Windows is Alt + 96
you can use string concatenation to achieve the same result, like this: