How can I get data from a field name when the name changes dynamically in Javascript? -


i have following code:

            switch (entitytype) {                 case "exam":                     entityid = formdata.examid;                     idcolumn = 'examid';                     break;                 case "subject":                     entityid = formdata.subjectid;                     idcolumn = 'subjectid';                     break;             } 

it's repeated more times showing 2 case values here. believe it's possible values idcolumn getting lowercase of entitytype , adding id. there way extract value in formdata field based on entitytype without having manually code many times.

you can replace whole with

  idcolumn = entitytype.tolowercase()+'id';   entityid = formdata[idcolumn]; 

i'd suggest read mdn's working objects.


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -