Hi -

Hopefully someone can help me. I am pretty new to this but here goes.

I have this code that dynamically creates these list boxes and when I am doing an update I need to set the selected value for the list box.

I know I am doing an update when #numberofTitleBoxes (a hidden field) exists.

This code creates the correct number of boxes and populates the drop down on the list boxes but I am just unsure of where to assign the selected value at.

I have hidden fields on the form with the value(s) they are supposed to be. The hidden fields IDs are like:

The numbers go up depending on how many list boxes are required. If only 1 list box there will only be one hidden field called Hidden1.

The value of the hidden field should equal the value of the list box that I want selected.

Any help would be greatly appreciated!

javascript Code:
       //initialize Titles with 1
        var startingTiNo = 0;
        var startTitleCount = 1;
        var displayTiCount = 1;
        var $node = "";
        data = textFileToArray("../title.txt");
        var empTitles = [];
        for (var i = 0; i < data.length; i++) {
            empTitles[i] = data[i].split('|');
        // If the number of Title Boxes needed exists populate Count for loop
        if ($('#numberofTitleBoxes').length) {
            startTitleCount = $('#numberofTitleBoxes').val();
        // Loop thru creating the ListBoxes 
        for (var x = 0; x < startTitleCount; x++) {
            $node += '<p><label for="title' + displayTiCount + '">Title: </label><select name="title' + displayTiCount + '" id="title' + displayTiCount + '">';
            for (titleCount = 0; titleCount < empTitles.length; titleCount++) {
                $node += '<option value ="' + empTitles[titleCount][0] + '">' + empTitles[titleCount][1] + '</option>';
            $node += '</select>&nbsp;&nbsp;<span class="removeTitle">Remove Title</span></p>';
            $node = "";
        // Reset the startTitleCount after adding list boxes
        startTitleCount = 0;