2017-05-26 27 views
0

他の入力フィールドを自動的に入力し、選択したフィールドの値に対してデータベースベースから読み取り専用にするか、値が割り当てられていない場合は空にしますか?データベースからの選択フィールドの値に基づいて自動入力フォームフィールド

<?php 
//include auth.php file on all secure pages 
require("../db.php"); 
session_start(); 
if(!isset($_SESSION["username"])){ 
header("Location: login"); 
exit(); } 
?> 
<?php require_once('header.php')?> 

<div class="container content"> 
    <h2>Add Shipment</h2> 



<script type="text/javascript"> 


$(document).ready(function(){ 

    txt=$("#ShipmentCustomerid").val(); 

     if(txt=='0') 
     { 
      fun1=''; 



    $("#ShipmentShipperphone").removeAttr('readonly'); 

    $("#ShipmentShipperaddress").removeAttr('readonly'); 

    $("#ShipmentShippername").removeAttr('readonly'); 


    $("#ShipmentShipperemail").removeAttr('readonly'); 

     } 

     else 
     { 
      gum1='';    

     $("#ShipmentShipperphone").attr('readonly',true); 

      $("#ShipmentShipperaddress").attr('readonly',true); 

     $("#ShipmentShippername").attr('readonly',true); 
     $.get("Shipperphone/"+txt,{ },function(result){ 
      result = $.trim(result) 
     $("#ShipmentShipperphone").val(result); 


    }); 

     $.get("Shipperaddress/"+txt,{ },function(result){ 
      result = $.trim(result) 
     $("#ShipmentShipperaddress").val(result); 


    }); 


     $.get("newshippername/"+txt,{ },function(result){ 
      result = $.trim(result) 
     $("#ShipmentShippername").val(result); 


    }); 



    $.get("shipperemail/"+txt,{ },function(result){ 
      result = $.trim(result) 
     $("#ShipmentShipperemail").val(result); 


    }); 



     } 


    $("#ShipmentCustomerid").change(function(){ 

    txt=$("#ShipmentCustomerid").val(); 

     if(txt=='0') 
     { 
      fun=''; 

      $("#ShipmentShipperphone").removeAttr('readonly'); 

      $("#ShipmentShipperaddress").removeAttr('readonly'); 
      $("#ShipmentShippername").removeAttr('readonly'); 

      $("#ShipmentShipperphone").val(fun); 

      $("#ShipmentShipperaddress").val(fun); 

      $("#ShipmentShippername").val(fun); 

      $("#ShipmentShipperemail").val(fun); 

      $("#ShipmentShipperemail").removeAttr('readonly'); 

     } 

     else 
     { 
      gum=''; 


     $("#ShipmentShipperphone").attr('readonly',true); 

      $("#ShipmentShipperaddress").attr('readonly',true); 

     $("#ShipmentShippername").attr('readonly',true); 

     $("#ShipmentShipperemail").attr('readonly',true); 

     $.get("Shipperphone/"+txt,{ },function(result){ 

     $("#ShipmentShipperphone").val(result); 


    }); 

     $.get("Shipperaddress/"+txt,{ },function(result){ 

     $("#ShipmentShipperaddress").val(result); 


    }); 

    $.get("Shipperphone/"+txt,{ },function(result){ 
      result = $.trim(result) 
     $("#ShipmentShipperphone").val(result); 


    }); 

    $.get("newshippername/"+txt,{ },function(result){ 
      result = $.trim(result) 
     $("#ShipmentShippername").val(result); 


    }); 
$.get("shipperemail/"+txt,{ },function(result){ 
      result = $.trim(result) 
     $("#ShipmentShipperemail").val(result); 


    }); 



     } 


    }); 
}); 

</script> 
<div id="test"></div> 
<div class="col-md-4"> 


<form action="add_shipment" id="ShipmentAddForm" method="post" accept-charset="utf-8"> 
    <div class="form-group"> 
    <h4>Shipper info :</h4> 
    </div> 

    <div class="form-group"><label for="ShipmentCustomerid">Choose</label><select name="id" class="form-control" id="ShipmentCustomerid"> 
<option value="0">Unassigned</option> 
<?php 
$result = mysqli_query($con,"SELECT Id,customername,phone,address,email FROM customer"); 
       while($row = mysqli_fetch_array($result)) { 
     ?> 
      <option value="<?=$row[0]?>"><?=$row[1]?></option> 
     <?php } 
    ?> 
</select></div> 

    <div class="form-group required"><label for="ShipmentShippername">Shippername</label><input name="" class="form-control" maxlength="35" type="text" id="ShipmentShippername" required="required"/></div> 
      <div class="form-group"><label for="ShipmentShipperphone">Phone</label><input name="" class="form-control" readonly="readonly" maxlength="30" type="text" id="ShipmentShipperphone"/></div>  



<div class="form-group required"><label for="ShipmentShipperaddress">Address</label><textarea name="" id="ShipmentShipperaddress" class="form-control" readonly="readonly" cols="30" rows="6" required="required"></textarea></div>  



    <div class="form-group"><label for="ShipmentShipperemail">Email</label><input name="]" class="form-control" readonly="readonly" maxlength="55" type="text" id="ShipmentShipperemail"/> 

    </div>   

ここにコードがあり、それをより良くするための貢献度が増します。

答えて

1

ajax投稿を使用するか、自動補完用に取得する必要があります。

参照:http://phppot.com/jquery/jquery-ajax-autocomplete-country-example/

// AJAX call for autocomplete 
$(document).ready(function(){ 
    $("#search-box").keyup(function(){ 
    $.ajax({ 
    type: "POST", 
    url: "readCountry.php", 
    data:'keyword='+$(this).val(), 
    beforeSend: function(){ 
     $("#search-box").css("background","#FFF url(LoaderIcon.gif) 
    no-repeat 165px"); 
    }, 
    success: function(data){ 
     $("#suggesstion-box").show(); 
     $("#suggesstion-box").html(data); 
     $("#search-box").css("background","#FFF"); 
     } 
     }); 
    }); 
}); 
//To select country name 
function selectCountry(val) { 
$("#search-box").val(val); 
$("#suggesstion-box").hide(); 
} 
+0

助け、それはWOKことができる方法の一例として、私のコードを使用します – phemieny7

関連する問題