如何在选择下拉列表中添加表单集

时间:2016-11-14 03:40:03

标签: php jquery mysql dropdown

我不知道从哪里开始。我有一个下拉列表和onchange它将传递2个值。从它我需要在设置上附加表单集(从我传递的值中选择数据库中的查询)

的index.php

    <div class="form-group">
    <label for="add-name" class="col-sm-4 control-label">Staff</label>
    <div class="col-sm-8">
        <?php 
        $sqlEmpSelect = "select * from payroll_emp order by emp_name";
        $qryEmpSelect = sqlsrv_query( $conn, $sqlEmpSelect ); 
        ?>
        <select name="dpEmp" id="dpEmp" class="form-control">
            <option>Sila Pilih</option>
            <?php while( $rowAllow = sqlsrv_fetch_array( $qryEmpSelect, SQLSRV_FETCH_ASSOC) ) { ?>
            <option value="<?=$rowAllow['emp_id']?>"><?=$rowAllow['emp_name']?></option>
            <?php
        }
        sqlsrv_free_stmt($qryEmpSelect);
        ?>
    </select>
</div>
</div>
<div class="form-group">
    <label for="add-template" class="col-sm-4 control-label">Template</label>
    <div class="col-sm-8">
        <select name="dpTemp" id="dpTemp" class="form-control">
            <option value="">Sila Pilih</option>
            <?php
            $sqlTemp = sprintf("select * from payroll_template order by template_name");
            $qryTemp = mysql_query($sqlTemp) or die(mysql_error());
            while ($resTemp = mysql_fetch_assoc($qryTemp)) {
                ?>
                <option value="<?php echo $resTemp['template_id']; ?>"/><?php echo $resTemp['template_name']; ?></option>
                <?php } ?>
            </select>  
        </div>
    </div>
    <div id="div-data" name="div-data"></div>

这里的jquery我尝试使用它..

$('#div-data').hide();
$('#dpTemp').change(function(){
    var empvalue = $('#dpEmp').val();
    var tempvalue = $('#dpTemp').val();
    if(tempvalue != ""){
        $.ajax({
            type:'get',
            url:'kew8/htmlforms.php',
            data:'empid=' + empvalue + '&tempid=' + tempvalue,
            success:function(html){
                $('#div-data').html(html);
            }
        }); 
    } else{
        $('#div-data').hide();
    }
});

这里我尝试调用表单集.. htmlforms.php

    <?php
        $sqlselect = "bla bla bla";
        $result = "";

        if ($result[0]['seeting1'] == 1) {
    ?>

    <div class="form-group">
        <label for="add-template" class="col-sm-4 control-label">Template</label>
        <div class="col-sm-8">
            <select name="dpTemp" id="dpTemp" class="form-control">
                <option value="">Sila Pilih</option>
            </select>  
        </div>
    </div>
    <div class="form-group">
        <label for="add-desc" class="col-sm-4 control-label">Keterangan</label>
        <div class="col-sm-8">
            <textarea id="txtDesc" name="txtDesc" class="form-control"></textarea>
        </div>
    </div>


<?php
}

if ($result[0]['seeting2'] == 2) {
?>

<div class="form-group">
        <label for="add-template" class="col-sm-4 control-label">Template</label>
        <div class="col-sm-8">
            <select name="dpTemp" id="dpTemp" class="form-control">
                <option value="">Sila Pilih</option>
            </select>  
        </div>
    </div>
    <div class="form-group">
        <label for="add-desc" class="col-sm-4 control-label">Keterangan</label>
        <div class="col-sm-8">
            <textarea id="txtDesc" name="txtDesc" class="form-control"></textarea>
        </div>
    </div>

<?php } ?>

and more setting

0 个答案:

没有答案