0

i don't know where to start. i have a dropdown list and onchange it will pass 2 values. from it i need to append form set base on setting (select query from database from the value i pass)

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>

here the jquery i try to use it..

$('#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();
    }
});

here i try to call the forms set.. 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
achimet
  • 75
  • 6
  • (1) This is too much code. You can't just dump all this here and expect us to read all of it. (2) Why are you using both `sqlsrv_` and `mysql_` database functions? (3) If you indeed want to use MySQL, consider moving away from the `mysql_` functions. They were deprecated in PHP 5.5, which is so old it doesn't even receive security updates anymore, and completely removed in PHP 7. Use PDO or `mysqli_` instead. See https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php for details. – ChrisGPT was on strike Nov 14 '16 at 03:43
  • tq for reading my question. i just want to know how to append form set base on the dropdown value. maybe u dont want to read the entire code but i hope someone will and give me an answer. – achimet Nov 14 '16 at 03:47
  • I don't get it, you want to append the form set yet you use `.html()` instead of `.append()`? – Mark Vincent Manjac Nov 14 '16 at 03:56
  • i'm tring .html().. that why im asking here.. i want the output from htmlforms.php page – achimet Nov 14 '16 at 04:09

0 Answers0