使用select选项的PHP JQuery Ajax内联编辑

时间:2016-11-07 14:43:25

标签: php jquery sql-server ajax inline

我使用的是php jquery ajax内联编辑系统,它按照预期的方式工作,直到我添加一个选择选项列表。下面是我正在处理的项目中的jquery和php / html布局,除了select选项外,每次保存到数据库都是正确的。

<script>
function showEdit(editableObj) {
    $(editableObj).css("background","#FFF");
} 

function saveToDatabase(editableObj,column,id) {
    $(editableObj).css("background","#FFF url(loaderIcon.gif) no-repeat right");
    $.ajax({
        url: "update_door_schedule.php",
        type: "POST",
        data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
        success: function(data){
            $(editableObj).css("background","#FDFDFD");
        }        
    });
}

<td class="left" contenteditable="true" onBlur="saveToDatabase(this,'[Date and Time Entered]','<?php echo $schedule_row['id']; ?>')" onClick="showEdit(this);"><?php echo $schedule_row['Date and Time Entered']; ?></td>
        <td class="left" contenteditable="true" onBlur="saveToDatabase(this,'[Door Number]','<?php echo $schedule_row['id']; ?>')" onClick="showEdit(this);"><?php echo $schedule_row['Door Number']; ?></td>
        <td class="left" contenteditable="true" onBlur="saveToDatabase(this,'[Customer Xref]','<?php echo $schedule_row['id']; ?>')" onClick="showEdit(this);"><?php echo $schedule_row['Customer Xref']; ?></td>
        <td class="left" contenteditable="true" onBlur="saveToDatabase(this,'[Interior or Exterior]','<?php echo $schedule_row['id']; ?>')" onClick="showEdit(this);">
            <select class="input-clearfit">
                <?php if($schedule_row['Interior or Exterior'] > ' '){ ?>
                    <option value="<?php echo $schedule_row['Interior or Exterior']; ?>" selected="selected"><?php echo $schedule_row['Interior or Exterior']; ?></option>
                <?php } ?>  
                <option value=""></option>
                <?php $result = sqlsrv_query($conn, "SELECT Product, [Sort Sequence]
                FROM DD_Product
                ORDER BY [Sort Sequence]"); 
                while ($list_row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { ?>
                    <option value="<?php echo $list_row['Product']; ?>"><?php echo $list_row['Product']; ?></option>
                <?php } ?>     
            </select>
        </td>

1 个答案:

答案 0 :(得分:0)

经过几次不同的变化和大量的谷歌搜索,答案就在我面前......

将innerhtml()替换为val()并放置输入字段和/或选择td中的选项菜单。