【发布时间】:2014-04-10 01:50:21
【问题描述】:
我试图在我的网页上完成某些操作时生成一些验证警报框,并且由于某种原因,在我将所有数据库调用放入单独的包含文件后,我的 Javascript 停止工作(在我这样做之前,javascript 正在工作)我尝试了我能想到的一切,但到目前为止没有任何效果,所以我来到最后的前沿寻求帮助,这是我启动数据库调用的 html 表单:
<form name="requestHol" action="newbooking.asp" method="post">
<div id="datepicker">
<label for="from">From </label>
<input type="text" id="from" name="from" readonly="readonly" >
<label for="to">to </label>
<input type="text" id="to" name="to" readonly="readonly" >
</div>
<div id="reason">
<textarea id="reasonInput" name="RequestComments" placeholder="Please enter the reason for your absence." maxlength="45" ></textarea>
</div>
<div id="reqbutton">
<button name="submitHolBtn" value="requestButton" type="submit">Submit Request</button>
</div>
</form>
这是我的 ASP 数据库调用:
If(Request.Form("submitHolBtn"))<>""Then
If(Request.Form("from"))="" or (Request.Form("to"))="" or (Request.Form("RequestComments"))="" Then
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""Please make sure you fill in ALL inputs when booking a holiday.""); location.href = 'newbooking.asp'</SCRIPT>")
else
Set objDBConn = Server.CreateObject("ADODB.Connection")
objDBConn.Open Application("ConnString")
Set objDBCommand = Server.CreateObject("ADODB.Command")
objDBCommand.ActiveConnection = objDBConn
objDBCommand.CommandText = "spNewHoliday"
objDBCommand.CommandType = adCmdStoredProc
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@StartDate", adDate, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@EndDate", adDate, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@EmployeeID", adVarChar, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@Reason", adVarChar, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@JobRoleID", adVarChar, adParamInput,200)
objDBCommand("@StartDate") = Request.Form("from")
objDBCommand("@EndDate") = Request.Form("to")
objDBCommand("@EmployeeID") = Session("UserID")
objDBCommand("@Reason") = Request.Form("RequestComments")
objDBCommand("@JobRoleID") = Session("JobRoleID")
Set objDBRS = Server.CreateObject("ADODB.RecordSet")
objDBRS.open objDBCommand,,adOpenForwardOnly
Session("IsBookingValid") = objDBRS(0)
SELECT CASE Session("IsBookingValid")
Case "HolidayBooked"
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""Holiday has been requested.""); location.href = 'newbooking.asp'</SCRIPT>")
Case "TooManyPeopleOfFSameJob"
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""Holiday CANNOT be booked, Max amount of employees with the same job role are off.""); location.href = 'newbooking.asp'</SCRIPT>")
Case "TooManyPeopleOff"
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""Holiday CANNOT be booked, Max amount of employees are already off.""); location.href = 'newbooking.asp'</SCRIPT>")
Case "YouHaveAlreadyBookedThisDateOff"
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""You have already booked these dates off.""); location.href = 'newbooking.asp'</SCRIPT>")
Case "YouCanOnlyBookAMaxOf10Days"
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""You can only book a max of 10 days off at a time.""); location.href = 'newbooking.asp'</SCRIPT>")
Case "YouDontHaveEnoughHolidaysLeft"
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""You do not have enough days left to book that holiday off.""); location.href = 'newbooking.asp'</SCRIPT>")
Case "YouHaveAlreadyBookedAHolidayInThatPeriod"
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""You already have a holiday booked off during that time period.""); location.href = 'newbooking.asp'</SCRIPT>")
END SELECT
Set objDBCommand=nothing
objDBConn.Close
Set objDBConn=nothing
end if
end if
感谢所有帮助:)
【问题讨论】:
-
您的问题是关于 JavaScript,所以请显示生成的 HTML 而不是 asp。
-
生成的 HTML 是没有 javascript 警报 @phylax 的正常页面
-
我不知道 asp 但你的 qouting 看起来不祥。
"<SCRIPT LANGUAGE=""JavaScript"">。应该是:'<SCRIPT LANGUAGE="JavaScript">'? -
不,那会注释掉代码@phylax
-
@phylax - 在经典 ASP 中,您可以使用双双引号来转义响应写入语句中的引号。例如
response.write "<div class=""myclass"">"将输出<div class="myclass">
标签: javascript html asp-classic alert