我需要一些PHP和JavaScript的帮助

编程入门 行业动态 更新时间:2024-10-06 16:28:02
本文介绍了我需要一些PHP和JavaScript的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为在线巴士预订系统做一个系统软件。检查可用性的预订部分具有输入目的地的必填字段。如果他们点击提交,弹出窗口显示,但是当我点击确定时,它会转到下一页,这是预订后应该做的事情。所以,我可以知道如何让用户单击确定并保持在同一页面上,直到所需字段输入数据,然后再继续下一页。如果您需要查看我的代码,请告诉我,因为它有点冗长。非常感谢。 代码的Javascript部分在这里:

I am doing a system software for an online bus booking system. The booking part to check availability has mandatory fields to enter destination..if they click submit, a pop up shows,but when i click ok it goes to the next page that is what it should do after booking is alright. So may i know how i can have the user click okay and stay on same page until the required fields have data entered before proceeding to next page. If you require to se my code, do let me know as it is a bit lengthy. Thank you a lot. the Javascript part of the code is here:

<script type="text/javascript"> function one(){ if(document.Form1.Destination.value==""){ alert("Please Chose your destination"); return true;} if(document.Form1.Date.value==""){ alert("Please chose a date"); return true;} if(document.Form1.Time.value=="");{ alert("Kindly chose your time of the day"); return true;} if(document.Form1.Adults.value=="");{ alert("Fill the number of Adults travelling"); return true;} if(document.Form1.Children.value=="");{ alert("Fill the number of children travelling"); return true;} } </script> <div class="bookform"> <button name="redirect" onClick="redirect()"> <form name="Form1" action="insert.php" method="post" onsubmit="return one()"> <h2><center>Check Availability <center></h2> <br> <center> <label> Destination:</label> <select name="Destination"> <option disabled selected value> -- select an option -- </option> <option value="op1"> Nairobi </option> <option value="op2"> Eldoret </option> <option value="op3"> Kisumu </option> <option value="op4"> Kericho </option> <option value="op5"> Mombasa </option> <option value="op6"> Kisii </option> <option value="op7"> Kampala </option> <option value="op8"> Voi </option> <option value="op9"> Kitale </option> <option value="op10"> Kakamega </option> </select> <br> <br> <label> Date:</label> <Input type= "Date" name="Date" max="10" id="date"> <br><br> <label> Time :</label> <select name="Time"> <option disabled selected value> -- select an option -- </option> <option value="op1"> Morning </option> <option value="op2"> Afternoon </option> <option value="op3"> Evening </option> </select> <br> <br> Number of Passengers: <br> <br> Adults: <br> <input type="text" name="Adults" size="5" maxlength="30"> <br> <center> Children: <br> <input type="text" name="Children" size="5" maxlength="30"> </center> <br> <br> <input type="submit" value="SUBMIT INFO" name="sb1" onclick="location.href='Availability.html'"> <input type="reset" value="Reset"> <br> <br> <br> </input> </center> </form>

我的尝试: 我试图搜索如何解决这个问题,或者如果细节没有填满我怎么能避免进入新页面。

What I have tried: I tried to search up for how to fix this, or how i can avoid going to a new page if details are not filled up.

推荐答案

在你的函数中,替换 return true; with return false; 。 如果所有验证通过,您将需要在函数底部返回返回true; 。 在你的一些 if 测试和下面的块之间也有一些杂散的分号。这些都需要删除,否则验证永远不会成功。 In your function, replace return true; with return false;. You will then need a return true; at the bottom of the function, if all validation passes. There are also some stray semi-colons between some of your if tests and the following block. These need to be removed, otherwise the validation will never succeed. function one(){ if (document.Form1.Destination.value==""){ alert("Please Chose your destination"); return false; } if (document.Form1.Date.value==""){ alert("Please chose a date"); return false; } if (document.Form1.Time.value==""){ alert("Kindly chose your time of the day"); return false; } if (document.Form1.Adults.value==""){ alert("Fill the number of Adults travelling"); return false; } if(document.Form1.Children.value==""){ alert("Fill the number of children travelling"); return false; } // All validation has passed: return true; }

更多推荐

我需要一些PHP和JavaScript的帮助

本文发布于:2023-11-02 06:23:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!