当从数据库中添加新的html表行选择值时为空

时间:2019-05-01 12:38:54

标签: javascript php html

请帮助 当我添加新行时,selectBox为空 我如何像下面的代码那样在新行$row[0]中收集价值?

<?php
require_once('templates/default/header.php');
session_start();
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
 $logres = "<div style= 'color:rgba(255, 255, 255, .5)' >Welcome to the member's area,&nbsp;" . $_SESSION['username'] . "!<div>";
} else {    
   header("location:./login.php");
}
?>
<?php
require_once('templates/default/footer.php');
$con = oci_connect("???", "???", "//??.??.??.??/???");
$stid = oci_parse($con, "SELECT * FROM items");
oci_execute($stid);
?>
<?php
require_once('templates/default/footer.php');
?>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
    <link rel="stylesheet" type="text/css" href="table/css/util.css">
    <link rel="stylesheet" type="text/css" href="table/css/main.css">   
    <div class="nav-scroller bg-white shadow-sm">
        <nav class="nav nav-underline">
        <meta name="viewport" content="width=device-width, initial-scale=1">
            <a class="nav-link active" href="users.php">All Users</a>            
            <a class="nav-link" href="users.php">Active Users</a>
            <a class="nav-link" href="users.php">Deactive Users</a>
        </nav>
    </div>
    <main role="main" class="container">
        <div class="d-flex align-items-center p-3 my-3 text-white-50 bg-purple rounded shadow-sm">
            <img class="mr-3" src="assets/img/liteAdmin-logo-512x512.png" alt="" width="48" height="48">
            <div class="lh-100">
                <h6 class="mb-0 text-white lh-100">Add New User</h6>
                <small>Fill Information Form</small>
                <small><?php echo $logres; ?></small>
            </div>
        </div>
    </main>
<main role="main" class="container">
        <div id="results">
            <table width="100%" border="1" cellspacing="0" cellpadding="5" id="productanddates" class="border"> 
            <tbody>
            <tr>
            <td class="cell100 column1inv">Select</td>
            <td class="cell100 column2inv">Item Name</td>
            <td class="cell100 column3inv">Price</td>
            <td class="cell100 column4inv">QTY</td>
            <td class="cell100 column5inv">Vat</td>
            <td class="cell100 column6inv">Total</td>
            </tr>
            <tr>            
            <td class="cell100 column1inv">
            <?php           
            echo  '<select class="myselect" style="width:500px;" name="Phonenumberdd1" id="Phonenumberdd1" onchange="ChooseContact(this)">';
            //'<select class="dd" name="Phonenumberdd1" id="Phonenumberdd1" style="width: 100%;" onchange="ChooseContact(this)">';
            while (($row = oci_fetch_array($stid, OCI_BOTH)) != false) {
            //echo $row[0];
            echo '<option value="' . htmlspecialchars($row[0]) . '">' . htmlspecialchars($row[0]) . '</option>';
            }
            echo '</select>';           
            ?>
            </td>
            <td class="cell100 column2inv"><input type="text" name="to1" id="to1" value="" style="width: 100%; background-color: #DCDCDC; color: #FFFFFF;" readonly= "true"></td>
            <td class="cell100 column3inv"><input type="text" name="price1" id="price1" style="width: 100%; background-color: #DCDCDC; color: #FFFFFF;"></td>           
            <td class="cell100 column4inv"><input type="text" name="qty1" id="qty1" style="width: 100%; background-color: #DCDCDC; color: #FFFFFF;"></td>
            <td class="cell100 column5inv"><input type="text" name="vat1" id="vat1" style="width: 100%; background-color: #DCDCDC; color: #FFFFFF;"></td>
            <td class="cell100 column6inv"><input type="text" name="total1" id="total1" style="width: 100%; background-color: #DCDCDC; color: #FFFFFF;"></td>           
            </tr>
            </tbody>
            </table>
        </div>
<input id="buttonclck" type="button" value="+"> 
</main>
<script type="text/javascript">
      $(".myselect").select2();
</script>
 <script type="text/javascript">  
    function ChooseContact(data) {
        document.getElementById ("to1").value = data.value;
    }
    $(function(){
    $('#results').on('focus', ':input', function() {
        $(this).closest('tr').filter(function() { 
            return !$(this).data('saved'); 
        })
        .find(':input').each(function() {
            $(this).data('value', this.value);
            $(this).closest('tr').data('saved', true);
        });
    })
    .on('input change', ':input', function() {
        $(this).data('filled', this.value != $(this).data('value'))
        var tr  = $(this).closest('tr');
            all = tr.find(':input'),
            fld = all.filter(function() {
                return $(this).data('filled');
            });
        if( all.length == fld.length ) {
            if( !tr.data('done') ) {
                $('#buttonclck')[0].click();
                tr.data('done', true);
            }
        } else {
            if( tr.data('done') ) {

                tr.data('done', false);
            }
        }
    });
    $('#buttonclck').on('click', function () {
        var lastRow = $('#productanddates').closest('#productanddates').find("tr:last-child");
        var lastRowInputs = lastRow.find('input');
        var isClone = false;
        lastRowInputs.each(function() {
           if($(this).val().length) {
               isClone = true;
           }
        });
        if(!isClone)
            return false;
        var cloned = lastRow.clone();
        cloned.find('input, select').each(function () {
            var id = $(this).attr('id');
            var regIdMatch = /^(.+)(\d+)$/;
            var aIdParts = id.match(regIdMatch);
            var newId = aIdParts[1] + (parseInt(aIdParts[2], 10) + 1);
            $(this).attr('id', newId);
            $(this).attr('name', newId);
        });
        cloned.find("input[type='text']").val('');      
        cloned.insertAfter(lastRow);
    });
    });
</script>
 <script>
    // tell the embed parent frame the height of the content
    if (window.parent && window.parent.parent){
      window.parent.parent.postMessage(["resultsFrame", {
        height: document.body.getBoundingClientRect().height,
        slug: "99pvwypp"
      }], "*")
    }
    // always overwrite window.name, in case users try to set it manually
    window.name = "result"
  </script>

0 个答案:

没有答案