2017-03-02 3 views
-1

Ich arbeite an einem Point of Sale-Projekt. Ich möchte bei der Auswahl eines Produkts den Produktpreis in einem anderen Feld wiedergeben. Ich kann keinen Weg finden, es zu tun. hier ist mein Codephp aus der Datenbank auswählen und mehrere Felder ausfüllen

<?php 
    include('../connect.php'); 
    $result = $db->prepare("SELECT * FROM products"); 
    $result->bindParam(':userid', $res); 
    $result->execute(); 
?> 
<form> 
    <select> 
    <?php 
     for ($i = 0; $row = $result->fetch(); $i++) { 
    ?> 
     <option value="<?php echo $row['product_id'];?>"> 
      <?php echo $row['product_code']; ?> 
      - 
      <?php echo $row['gen_name']; ?> 
     </option> 
    <?php } ?> 
    </select> 
    <input type="number" name="qty" min="1" placeholder="Qty" autocomplete="off" style="width: 68px; height:30px; padding-top:6px; padding-  bottom: 4px; margin-right: 4px; font-size:15px;"/required> 
    <input type="number" name="pc" max="25" placeholder="disc" autocomplete="off" style="width: 68px; height:30px; padding-top:6px; padding-bottom: 4px; margin-right: 4px; font-size:15px;" /> 
    <input type="number" name="price" max="25" value="price goes here " style="width: 68px; height:30px; padding-top:6px; padding-bottom: 4px; margin-right: 4px; font-size:15px;" /> 
    <input type="hidden" name="date" value="<?php echo date('m/d/y'); ?>"/> 
</form> 
+1

Ist ein Fehler aufgetreten? – Swellar

+1

Ich habe gerade festgestellt, dass Sie einen Parameter nicht in der Abfrage binden. – Swellar

+0

Oh, und vermeiden Sie die Verwendung von Inline-CSS, vor allem, wenn es viel – Swellar

Antwort

0

Sie in einem einfachen Weg mit Hilfe von Javascript zu tun, einen Blick in das Beispiel unten nehmen, so dass Sie den Preis überall Echo können, dass Sie juse mit der ID wollen oder was auch immer das ist gut für Sie

$("#mySelect").change(function(){ 
 
var price = $(this).val(); 
 
var fruitName = $(this).find(":selected").text(); 
 

 
$("#fruitPrince").text('You choose '+fruitName+' and the price is: $'+price); 
 

 
})
@import "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css";
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script> 
 
<div class="container-fluid"> 
 
    <select class="form-control" id="mySelect"> 
 
    <option selected disabled> Choose a Fruit </option> 
 
    <option value="10"> Banana </option> 
 
    <option value="5"> Apple </option> 
 
    <option value="3"> Orange </option> 
 
    </select> 
 
    <div class="bg-success"> 
 
    <p id="fruitPrince"> </p> 
 
    </div> 
 
</div>

0

Reynnan Sieger Beispiel verwendet. es hat für mich funktioniert. Hier ist der Code

<?php 
include('../connect.php'); 
$result = $db->prepare("SELECT * FROM products"); 
$result->execute(); 
for ($i = 0; $row = $result->fetch(); $i++) { 
?> 
<option value="<?php 
echo $row['price']; 
?>" ><?php 
echo $row['gen_name']; 
?> 
<?php 
echo $row['product_code']; 
?></option> 
<?php 
} 
?></select> 
<input type="number" name="qty" min="1" placeholder="Qty" required/> 
<text id="price" contenteditable="true" name="price"> 
<script>$("#mySelect").change(function(){ 
var price = $(this).val(); 
$("#price").text(price); 
})</script></text> 
Verwandte Themen