本文介绍了当我在淹没选项中选择未填写在meal_price输入框中的meal_name时,我的java脚本代码无法正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个java脚本代码,当我在选项框中选择meal_name时,我想用feed_price填写输入框。我的代码可能会出现问题。
下面是我的代码。
我尝试了什么:
<?php
// $ uid = $ _SESSION ['uid'];
if(isset($ _ SESSION ['uid'])){
echo $ _SESSION ['uid'];
}
include(../ dbConfig.php);
包括user_navigation.php;
包括../header.php;
包括../footer.php;
$ query =选择Max(meal_id)来自meal_table;
$ returnD = mysql_query($ query);
$ result = mysql_fetch_assoc($ returnD);
$ maxRows = $ result ['Max(meal_id)'];
if(空($ maxRows)){
$ lastRow = $ maxRows = 101;
} else {
$ lastRow = $ maxRows + 1;
}
?>
<?php
//请求餐费...
$ query =选择Max(meal_id)来自meal_table;
$ returnD = mysql_query($ query);
$ result = mysql_fetch_assoc($ returnD);
$ maxRows = $ result ['Max(meal_id)'];
if(空($ 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 /内罗毕');
$ 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', '$数量', '$ request_name', '$描述', '$ DT'));
if($ query){
$ errorMsg =你成功申请了一顿饭。;
}
}
else {
$ errorMsg =请!在空白字段中输入。;
}
header(location:user_main.php);
//include(\"requestFormeals.php);
}
?>
<! - < script type =text / javascript>
函数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>
函数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>请求用餐< / 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>
添加项目
< / div>
< div class =panel-body>
< div class =row>
< div class =col-lg-6>
< div class =panel-body>
< form role =formaction =>
< div class =row form-inline>
< fieldset>
< div class =form-group>
< input type =textname =requestidclass =form-controlvalue =<?php echo $ _SESSION ['uid']; ?>只读>
< / div>
< div class =form-group>
< input type =textname =meal_idclass =form-controlvalue =<?php echo $ lastRow; ?>只读>
< / div>
< div class =inputs>
< div class =form-group>
< select name =meal_namerequired autofocus onchange =meal_name(meal_name)onChange ='Choice();'>
< option value =>选择食物菜单< /选项>
<?php
$ query =select * from meal_menu_table;
$ res = mysql_query($ query)或die('错误查询');
while($ row = mysql_fetch_assoc($ res))
{
// echo< option>。$ row ['activity_name'];
echo< option value ='。 $ row ['meal_name']。 >中。 $ row ['meal_name']。 < /选项> 中;
}
?>
< / select>
< / div>
< / div>
< div class =form-group>
< input type =textname =meal_priceid =meal_priceclass =form-controlrequired autofocus placeholder =Meal_Pricereadonly>
< / div>
< div class =form-group>
< input type =textname =quantityclass =form-controlrequired autofocus placeholder =Number_of_Dishes>
< / div>
< div class =form-group>
< input type =textname =request_nameclass =form-controlrequired autofocus placeholder =Your-Name>
< / div>
< div class =form-group>
< textarea cols =35rows =3name =descriptionclass =form-controlplaceholder =Description and your location>< / textarea>
< / div>
< input type =submitname =mealRequestBtnvalue =Requestclass =btn btn-success btn-sm>
< br>
<?php
if(isset($ errorMsg)){
?>
< div class =errorMsg><?php echo $ errorMsg; ?>< / DIV>
<?php
}
?>
< / form>
< / div>
< / div>
<! - /.col-lg-6(嵌套) - >
< / div>
<! - /.row(嵌套) - >
< / div>
<! - /.panel-body - >
< / div>
<! - /.panel - >
< / div>
<! - /.col-lg-12 - >
< / div>
<! - /.row - >
< / div>
<! - / #page-wrapper - >
解决方案
i have a java script code that is suppose to fill in the input box with the meal_price when i select the meal_name in the option box.what could be the problem with my code.
Below is my code.
What I have tried:
<?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 -->
解决方案
这篇关于当我在淹没选项中选择未填写在meal_price输入框中的meal_name时,我的java脚本代码无法正常工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!