Мой код java-скрипта не работает, когда я выбираю meal_name в опции drown down, он не заполняет поле ввода meal_price.
у меня есть код java-скрипта, который, как предполагается, заполняет поле ввода meal_price, когда я выбираю meal_name в поле опций.в чем может быть проблема с моим кодом?
Ниже приведен мой код.
Что я уже пробовал:
<?php //$uid = $_SESSION['uid']; if(isset($_SESSION['uid'])){ echo $_SESSION['uid']; } include("../dbConfig.php"); include "user_navigation.php"; include "../header.php"; include "../footer.php"; $query = "Select Max(meal_id) From meal_table"; $returnD = mysql_query($query); $result = mysql_fetch_assoc($returnD); $maxRows = $result['Max(meal_id)']; if(empty($maxRows)){ $lastRow = $maxRows = 101; }else{ $lastRow = $maxRows + 1 ; } ?> <?php //REQUEST FOR Meals... $query = "Select Max(meal_id) From meal_table"; $returnD = mysql_query($query); $result = mysql_fetch_assoc($returnD); $maxRows = $result['Max(meal_id)']; if(empty($maxRows)){ $lastRow = $maxRows = 101; }else{ $lastRow = $maxRows + 1 ; } if (isset($_REQUEST['mealRequestBtn'])) { $requestid = $_REQUEST['requestid']; $meal_id = $_REQUEST['meal_id']; $meal_name = $_REQUEST['meal_name']; $meal_price = $_REQUEST['meal_price']; $quantity = $_REQUEST['quantity']; $request_name = $_REQUEST['request_name']; $description = $_REQUEST['description']; if(!empty($requestid) && !empty($meal_name) && !empty($request_name)){ date_default_timezone_set('Africa/Nairobi'); $dt = date("y/m/d h:i:s"); $query = mysql_query("INSERT INTO meal_table(requestid,meal_id,meal_name,meal_price,quantity,request_name,description,requestDate) VALUES('$requestid','$meal_id','$meal_name','$meal_price','$quantity','$request_name','$description','$dt')"); if ($query) { $errorMsg = "You successfully requested for a meal."; } } else{ $errorMsg = "Please! Enter in the empty field."; } header("location: user_main.php"); //include("requestFormeals.php"); } ?> <!-- <script type="text/javascript"> function getPrice(select) { var form = select.form; form.meal_price.value = select.options[select.selectedIndex].text; form.meal_name.value = select.value; } </script> --> <script type="text/javascript"> function Choice() { x = document.getElementById("meal_price"); y = document.getElementById("meal_name"); x.value = y.options[y.selectedIndex].text; } </script> <div id="page-wrapper"> <div class="row"> <div class="col-lg-12"> <h1 class="page-header">Request For Meals</h1> </div> <!-- /.col-lg-12 --> </div> <!-- /.row --> <div class="row"> <div class="col-md-4 col-md-offset-4"> <div class="Register-panel panel panel-default"> <!--div class="panel panel-default"--> <div class="panel-heading"> Add Items </div> <div class="panel-body"> <div class="row"> <div class="col-lg-6"> <div class="panel-body"> <form role="form" action=""> <div class="row form-inline"> <fieldset> <div class="form-group"> <input type="text" name="requestid" class="form-control" value=<?php echo $_SESSION['uid']; ?> readonly> </div> <div class="form-group"> <input type="text" name="meal_id" class="form-control" value=<?php echo $lastRow; ?> readonly> </div> <div class="inputs"> <div class="form-group"> <select name="meal_name" required autofocus onchange= "meal_name(meal_name)" onChange='Choice();'> <option value="">Select Food Menu</option> <?php $query="select * from meal_menu_table"; $res=mysql_query($query) or die('wrong query'); while($row=mysql_fetch_assoc($res)) { //echo "<option>".$row['activity_name']; echo "<option value='" . $row['meal_name'] . "'>" . $row['meal_name'] . "</option>"; } ?> </select> </div> </div> <div class="form-group"> <input type="text" name="meal_price" id="meal_price" class="form-control" required autofocus placeholder="Meal_Price" readonly > </div> <div class="form-group"> <input type="text" name="quantity" class="form-control" required autofocus placeholder="Number_of_Dishes" > </div> <div class="form-group"> <input type="text" name="request_name" class="form-control" required autofocus placeholder="Your-Name"> </div> <div class="form-group"> <textarea cols="35" rows="3" name="description" class="form-control" placeholder="Description and your location"></textarea> </div> <input type="submit" name="mealRequestBtn" value="Request" class="btn btn-success btn-sm"> <br> <?php if(isset($errorMsg)){ ?> <div class="errorMsg"><?php echo $errorMsg; ?></div> <?php } ?> </form> </div> </div> <!-- /.col-lg-6 (nested) --> </div> <!-- /.row (nested) --> </div> <!-- /.panel-body --> </div> <!-- /.panel --> </div> <!-- /.col-lg-12 --> </div> <!-- /.row --> </div> <!-- /#page-wrapper -->