Scorez2000
Programmer
Hi all.
The method of form validation I use is client-side vbscript within my ASP application. Within the form, instead of having a submit button, I have a normal button. Then there's a vbscript that runs when the button is clicked.
This all runs fine and works exactly how I want except for one thing. Within a normal HTML form, the user can submit the form from any field by pressing enter. However, my code will not work unless the button is actually clicked.
Is there a way of making the form act like a normal web form (i.e. submit when the user presses enter).
Here is a sample of my code.
-----------------------------------------------------------
<html>
<head>
<script language="vbscript">
Sub btnSubmit_OnClick()
if requestleave.leavetype.value = "0" then
Alert "Please select the type of leave applied for."
Exit Sub
elseif isdate(requestleave.rlFirst.value) = false then
Alert "Please enter a valid date for the first day of leave."
requestleave.rlFirst.focus
Exit Sub
elseif isdate(requestleave.rlLast.value) = false then
Alert "Please enter a valid date for the last day of leave."
requestleave.rlLast.focus
Exit Sub
elseif cdate(requestleave.rlFirst.value) > cdate(requestleave.rlLast.value) then
Alert "The last day of leave must be after or the same as the first day of leave."
Exit Sub
elseif cdate(requestleave.rlFirst.value) = cdate(requestleave.rlLast.value) and requestleave.cblast.checked = True then
Alert "When booking a half day, only use the upper tickbox for selecting a half day"
Exit Sub
End If
if cdate(requestleave.rlFirst.value) <=date() then
btnSubmitClicked = MsgBox ("This leave request is in the past. Are you sure you want to continue?", VBYesNo, "Please Confirm")
If btnSubmitClicked = 6 then
Call requestleave.Submit()
end if
else
Call requestleave.Submit()
end if
End Sub
</script>
</head>
<body>
<h3>Leave Request</h3>
<table>
<form name="RequestLeave" id="RequestLeave" method="post" action="requestLeavedetails.asp">
<tr>
<td colspan="3"><b>Type Of Leave Applied for:</b></td>
<td colspan="4" align="right">
<select name="leavetype" id="leavetype">
<option value="0"></option>
<%
Set rsLeaveType = Conn.Execute("SELECT AbsenceType.AbsenceTypeID, AbsenceType.AbsenceType FROM AbsenceType WHERE (((AbsenceType.AbsenceType)=""Holiday"")) OR (((AbsenceType.AbsenceType)=""Special Leave"")) ORDER BY AbsenceType.AbsenceType;")
while rsLeaveType.EOF = "False"
Response.Write("<option value=""" & rsLeaveType("AbsenceTypeID") & """>" & rsLeaveType("AbsenceType") & "</option>")
rsLeaveType.movenext
wend
%>
</select>
</td>
</tr>
<tr>
<td colspan="6" align="center" style="font-size:xx-small">Use the tick boxes to mark the first or last day as half days. Then use the drop down to choose AM/PM for that day. If only one day is being taken, use the top box and dropdown.</td>
</tr>
<tr>
<td>Date:
<td><input id="rlFirst" name="rlFirst" size="7" maxlength="10"></td>
<td><input type="checkbox" id="cbFirst" name="cbFirst"></td>
<td>
<select name="ampmFirst" id="ampmFirst">
<option>AM</option>
<option>PM</option>
</select>
</td>
<tr>
<td>Date:
<td><input id="rlLast" name="rlLast" size="7" maxlength="10"></td>
<td><input type="checkbox" id="cbLast" name="cbLast">
<td>
<select name="ampmLast" id="ampmLast">
<option>AM</option>
<option>PM</option>
</select>
</td>
</tr>
<tr>
<td colspan="7" align="right"><input type="button" value="Next..." id="btnSubmit" name="btnSubmit"></td>
</tr>
</form>
</table>
</body>
</html>
The method of form validation I use is client-side vbscript within my ASP application. Within the form, instead of having a submit button, I have a normal button. Then there's a vbscript that runs when the button is clicked.
This all runs fine and works exactly how I want except for one thing. Within a normal HTML form, the user can submit the form from any field by pressing enter. However, my code will not work unless the button is actually clicked.
Is there a way of making the form act like a normal web form (i.e. submit when the user presses enter).
Here is a sample of my code.
-----------------------------------------------------------
<html>
<head>
<script language="vbscript">
Sub btnSubmit_OnClick()
if requestleave.leavetype.value = "0" then
Alert "Please select the type of leave applied for."
Exit Sub
elseif isdate(requestleave.rlFirst.value) = false then
Alert "Please enter a valid date for the first day of leave."
requestleave.rlFirst.focus
Exit Sub
elseif isdate(requestleave.rlLast.value) = false then
Alert "Please enter a valid date for the last day of leave."
requestleave.rlLast.focus
Exit Sub
elseif cdate(requestleave.rlFirst.value) > cdate(requestleave.rlLast.value) then
Alert "The last day of leave must be after or the same as the first day of leave."
Exit Sub
elseif cdate(requestleave.rlFirst.value) = cdate(requestleave.rlLast.value) and requestleave.cblast.checked = True then
Alert "When booking a half day, only use the upper tickbox for selecting a half day"
Exit Sub
End If
if cdate(requestleave.rlFirst.value) <=date() then
btnSubmitClicked = MsgBox ("This leave request is in the past. Are you sure you want to continue?", VBYesNo, "Please Confirm")
If btnSubmitClicked = 6 then
Call requestleave.Submit()
end if
else
Call requestleave.Submit()
end if
End Sub
</script>
</head>
<body>
<h3>Leave Request</h3>
<table>
<form name="RequestLeave" id="RequestLeave" method="post" action="requestLeavedetails.asp">
<tr>
<td colspan="3"><b>Type Of Leave Applied for:</b></td>
<td colspan="4" align="right">
<select name="leavetype" id="leavetype">
<option value="0"></option>
<%
Set rsLeaveType = Conn.Execute("SELECT AbsenceType.AbsenceTypeID, AbsenceType.AbsenceType FROM AbsenceType WHERE (((AbsenceType.AbsenceType)=""Holiday"")) OR (((AbsenceType.AbsenceType)=""Special Leave"")) ORDER BY AbsenceType.AbsenceType;")
while rsLeaveType.EOF = "False"
Response.Write("<option value=""" & rsLeaveType("AbsenceTypeID") & """>" & rsLeaveType("AbsenceType") & "</option>")
rsLeaveType.movenext
wend
%>
</select>
</td>
</tr>
<tr>
<td colspan="6" align="center" style="font-size:xx-small">Use the tick boxes to mark the first or last day as half days. Then use the drop down to choose AM/PM for that day. If only one day is being taken, use the top box and dropdown.</td>
</tr>
<tr>
<td>Date:
<td><input id="rlFirst" name="rlFirst" size="7" maxlength="10"></td>
<td><input type="checkbox" id="cbFirst" name="cbFirst"></td>
<td>
<select name="ampmFirst" id="ampmFirst">
<option>AM</option>
<option>PM</option>
</select>
</td>
<tr>
<td>Date:
<td><input id="rlLast" name="rlLast" size="7" maxlength="10"></td>
<td><input type="checkbox" id="cbLast" name="cbLast">
<td>
<select name="ampmLast" id="ampmLast">
<option>AM</option>
<option>PM</option>
</select>
</td>
</tr>
<tr>
<td colspan="7" align="right"><input type="button" value="Next..." id="btnSubmit" name="btnSubmit"></td>
</tr>
</form>
</table>
</body>
</html>