I have a form with a vb validation script. I'm close but it's still not quite running as I want. Details are as follows:
<form name="frmMyForm" method="post" action="action.asp">
'selects & radio groups snipped here...
<input type="submit" name="Cmd_Validate" value="Submit">
<%
response.write "<script Language = ""VBScript"">" & VbCrlf
response.write " <!-- " & vbcrlfs
response.write "'Form Validation for form frmMyForm" & VbCrlf
response.write "sub Cmd_Validate_onclick()" & VbCrlf
dim farray(22,1)
'declare the array variables
farray(0,0) = "selectItem1"
farray(0,1) = "Please Select Item 1"
farray(1,0) = "selectItem2"
farray(1,1) = "Please Select Item 2"
etc...
farray(22,0) = "radioLastItem"
farray(22,1) = "Please select Last Item"
'validation code for the page
for i = 0 to ubound((farray),1)
'values for the select boxes
if i < 3 then
response.write "if frmMyForm." & farray(i,0) & ".value = 0 then" & VbCrlf
response.write "msgbox(""" & farray(i,1) & """
" & VbCrlf
response.write " frmMyForm." & farray(i,0) & ".focus " & VbCrlf
i = i + 1
response.write "elseif frmMyForm." & farray(i,0) & ".value = 0 then" & VbCrlf
response.write "msgbox(""" & farray(i, 1) & """
" & VbCrlf
response.write " frmMyForm." & farray(i,0) & ".focus " & VbCrlf
i = i + 1
response.write "elseif frmMyForm." & farray(i,0) & ".value = 0 then" & VbCrlf
response.write "msgbox(""" & farray(i,1) & """
" & VbCrlf
response.write " frmMyForm." & farray(i,0) & ".focus " & VbCrlf
i = i + 1
else
end if
'values for the radios
response.write "elseif frmMyForm." & farray(i,0) & "(0).checked = false and frmMyForm." & farray(i,0) & "(1).checked = false and frmMyForm." & farray(i,0) & "(2).checked = false then" & VbCrlf
response.write "msgbox(""" & farray(i,1) & """
" & VbCrlf
response.write " frmMyForm." & farray(i,0) & "(2).focus " & VbCrlf
next
response.write "end if " & VbCrlf
response.write "end sub" & VbCrlf
response.write " //-->" & Vbcrlf
response.write ("</script>"
%>
</form>
If all of my form fields are filled in, my form data posts to my db.
If I leave blank fields, the validation script kicks in and prompts with an alert. When I OK the alert, focus should go to the missing field...it does not. Instead, the form attempts to post but errors out because I am missing field data.
Can anyone see how that might be accomplished?
Thanks in advance.
<form name="frmMyForm" method="post" action="action.asp">
'selects & radio groups snipped here...
<input type="submit" name="Cmd_Validate" value="Submit">
<%
response.write "<script Language = ""VBScript"">" & VbCrlf
response.write " <!-- " & vbcrlfs
response.write "'Form Validation for form frmMyForm" & VbCrlf
response.write "sub Cmd_Validate_onclick()" & VbCrlf
dim farray(22,1)
'declare the array variables
farray(0,0) = "selectItem1"
farray(0,1) = "Please Select Item 1"
farray(1,0) = "selectItem2"
farray(1,1) = "Please Select Item 2"
etc...
farray(22,0) = "radioLastItem"
farray(22,1) = "Please select Last Item"
'validation code for the page
for i = 0 to ubound((farray),1)
'values for the select boxes
if i < 3 then
response.write "if frmMyForm." & farray(i,0) & ".value = 0 then" & VbCrlf
response.write "msgbox(""" & farray(i,1) & """
response.write " frmMyForm." & farray(i,0) & ".focus " & VbCrlf
i = i + 1
response.write "elseif frmMyForm." & farray(i,0) & ".value = 0 then" & VbCrlf
response.write "msgbox(""" & farray(i, 1) & """
response.write " frmMyForm." & farray(i,0) & ".focus " & VbCrlf
i = i + 1
response.write "elseif frmMyForm." & farray(i,0) & ".value = 0 then" & VbCrlf
response.write "msgbox(""" & farray(i,1) & """
response.write " frmMyForm." & farray(i,0) & ".focus " & VbCrlf
i = i + 1
else
end if
'values for the radios
response.write "elseif frmMyForm." & farray(i,0) & "(0).checked = false and frmMyForm." & farray(i,0) & "(1).checked = false and frmMyForm." & farray(i,0) & "(2).checked = false then" & VbCrlf
response.write "msgbox(""" & farray(i,1) & """
response.write " frmMyForm." & farray(i,0) & "(2).focus " & VbCrlf
next
response.write "end if " & VbCrlf
response.write "end sub" & VbCrlf
response.write " //-->" & Vbcrlf
response.write ("</script>"
%>
</form>
If all of my form fields are filled in, my form data posts to my db.
If I leave blank fields, the validation script kicks in and prompts with an alert. When I OK the alert, focus should go to the missing field...it does not. Instead, the form attempts to post but errors out because I am missing field data.
Can anyone see how that might be accomplished?
Thanks in advance.