Pre select list box in Ajax results
Posted on 2013-11-23
I am working with php/mysql. I am doing an Ajax fetch from mysql. In the reply I am building a table which contains a list box. I want to preselect the value in the box based on a value being fetched.
I wrote the fetched value to a hidden field in the table, and tried using a js preselect function to loop through the options , selecting the one that matches the value in the hidden field.
I can't get the js function to see hidden field value.
The js preselect function is fired right after the Ajax call.? Do I need to let things settle before I can access the table contents??
If there is a better way to do this please let me know.
My php file attached:
JS function below:
var itemToSelect = form1.current_status.value;
var myDropdownList = document.New_Status.lstNames;
for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++)
if (myDropdownList.options[iLoop].value == itemToSelect)
myDropdownList.options[iLoop].selected = true;