Problem with val in dialog
Hi,
I am having a problem with a VAL() call. I have a page with a button that brings up a dialog to edit values. When the user presses save, I save the values and then call them up again if they edit again. So, here's what happens when the user presses "Edit".
1) Read the values that should go into the Text boxes on the dialog
2) Rebuild the HTML that goes into the dialog div
3) Assign the HTML to the DIV and call the dialog() method to set it up
4) Assign the values to the text boxes using .val()
5) Show the dialog
The dialog shows all the values the first and second times it is called but in the THIRD time the text boxes are all blank.
I have traced through the code and I can see the val being called and I can see that the element being sent through on the val() call has a value. It just isn't showing.
Here's the basics of the code:
- function editLevels(){
- //Step one - Get the levels from its storing place
- var strLevels = $("#hidLevels").val();
- var aLevels = $.parseJSON(strLevels);
- var htmlCode = '<div id="divEditLevels">' +
- '<table name="tblEditLevels" id="tblEditLevels" class="display compact" width="99%">' +
- '<thead><tr><th>Temperature</th><th>Pre</th><th>Post</th><th> </th></tr></thead><tbody id="tblLevelsBody">';
-
- var aTextObjects = new Array();
- var iNumObjects = 0;
- //aVals has one row for each value I have to show. The level is a level identifier.
- //There must be at least one level but there can be any number of them.
- //Users can add or delete levels.
-
- $.each(aVals, function(avIndex, data){
- var idLowName = "txtLow" + data['iLevel'];
- var idHighName = "txtHigh" + data['iLevel'];
- var idRemoveName = "cmdRemove" + data['iLevel'];
- var idRow = "tr" + + data['iLevel'];
-
- aTextObjects[iNumObjects] = data['iLevel'] + "|" + data['decMeasureLow'] + "|" + data['decMeasureHigh'];
- iNumObjects++;
-
- htmlCode = htmlCode + '<tr id="' + idRow + '"><td>' + data['iLevel'] + "</td>" +
- "<td>" +
- '<input type="text" id="' + idLowName + '" ' +
- 'name="' + idLowName + '" style="width:50px;text-align:right;" /></td>' +
- '<td>' +
- '<input type="text" id="' + idHighName + '" ' +
- 'name="' + idHighName + '" style="width:50px;text-align:right;" /><td>' +
- '<input type="button" value="Remove" class="RemoveButton" id="' + idRemoveName + '" /></td></tr>';
- });
-
- htmlCode = htmlCode + '</tbody></table>';
- htmlCode = htmlCode + '<p style="text-align:right">';
- htmlCode = htmlCode + '<input type="button" value = "Add Level" id="cmdEditLevelAdd" />';
- htmlCode = htmlCode + '<input type="hidden" id="hidEditLevelResults" value = "" /> </p>';
- htmlCode = htmlCode + '</div>';
-
- $("#divEditLevels").html("");
-
- var divEditLevels = $(htmlCode).dialog({
- height: "auto",
- width: "auto",
- modal: true,
- title: "Edit Levels",
- position: {my: "center", at: "top+200", of: window},
- buttons:[
- { text: "Save",
- click: function(){
- $("#hidEditLevelResults").val("Save");
- $(this).dialog("close");
- saveLevels();
- }
- },
- {text: "Cancel",
- click: function(){
- $("#hidEditLevelResults").val("Cancel");
- $(this).dialog("close");
- }
- }
- ]
- });
-
- $.each(aTextObjects, function(idxObject, cTxtContents){
- var aValues = cTxtContents.split("|");
- var cObjName;
-
- // First column is the Level
- // Second is the Low Measurement
- // Third is the High Measurement
-
- cObjName = "txtLow" + aValues[0];
- $("#"+cObjName).val(aValues[1]);
- //$("#"+cObjName).attr("value", aValues[1]);
-
- cObjName = "txtHigh" + aValues[0];
- $("#"+cObjName).val(aValues[2]);
- //$("#"+cObjName).attr("value", aValues[2]);
- });
-
- // Some additional code to handle click events on the dialog snipped out
- }
Again, the .val() code works the first two times it is called. The third does not seem to do work. I am at a loss. Any ideas would be greatly appreciated.
Thanks