I have a dynamic table with a dropdown list in one of the columns. That list is being populated with a database lookup.
When the form loads and when a row is added, the dropdown value is "undefined" . I want the default of the dropdown to be "0000".
I've written some javascript that sets the default of all dropdowns whose value is "undefined" in the column. It's run when the form loads and when a user clicks on the "Add" link to add another row. But I can't seem to get it to set the default when the form loads. It leaves the dropdown list blank. Once a user clicks the "Add" link, it sets the default of all undefined dropdowns in the column to "0000".
With the use of some alerts, I could see that the code inside the if statement is being invoked on form load and for every new row created. Not sure why the field doesn't show the default value.
Any help would be appreciated!
Here's how I'm doing it:
setClientIDDefault(); $(document).on('click','#q11', setClientIDDefault); function setClientIDDefault() { var clientID; // for each row in table $('#q12 tbody tr').each(function () { if ( clientID === undefined ) { // set default client id to 0000 $(this).find($('select[id^=Field28]')).val("0000"); } }); }
q11 is the "Add" link, q12 is the table, and Field28 is the dropdown control.