Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Control Name Access 1

Status
Not open for further replies.

amrmnabil

MIS
Jun 2, 2017
10
0
0
EG
Hi All;
I have a form with inputs created dynamically. Their names are generated like
newpackqty1, newpackqty2, newpackqty3, and so on.
I am trying to validate that at least on of these controls has value this is my Code
for (let i = 1; i <= parseInt(lblCount.value); i++) {
let newqty = 'newpackqty'+i.toString();
if ($("input[name=newqty]").val() == 0) {
noSrcLabels = true;
break;
}​
This code does not run, and doesn't generate an error, the watch window gives this result:
watch_dp0z0x.png


I am new to javascript, and JQuery, What am i doing wrong??

Thanks

 
Hi

In JavaScript no string interpolation is performed in regular strings. Change it to template string :
Code:
if ($(`input[name="${ newqty }"]`).val() == 0) {

Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top