For Programmers: Free Programming Magazines  


Home > Archive > ASP > October 2006 > validating input boxes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author validating input boxes
MadMike42

2006-10-30, 9:55 pm

This is really starting to annoy me,
I've got a form, that has some input boxes,
a example of the code is here:-

<form action="admin_save_stock.asp" method="post" name="MyFormData">
<input name="Make" type="text" id="MenuText" value=<% response.write
rsTable("Make") %> size="50" maxlength="50">
<input name="DateBought" id="MenuText" type="text" value=<% response.write
rsTable("DateBought") %> size="10" maxlength="10">
</form>

I also have a FUNCTION that checks to make sure the dates etc are correct :-
But, the code will work as far as giving me the error MSGBOX
but it still posts to the next page for some reason its
ignoring the " MyFormData_OnSubmit = False "

Why ?

<Script language="vbscript">
Function MyFormData_OnSubmit()
Dim FormOkay

FormOkay=True

if isdate(MyFormData.DateBought.Value)=False then
msgbox "Error in date", vbokayonly+vbinformation,"Checking Data"
MyFormData.DateBought.SetFocus
FormOkay=False
end if

if FormOkay=False then
MyFormData_OnSubmit = False
else
MyFormData_OnSubmit = True
end if

end Function
</Script>

thankls
Mike.


Jon Paal

2006-10-30, 9:55 pm

I don't think there is a "setfocus"

try this
=============================

<Script language="vbscript">

Function validate()

Dim FormOkay
FormOkay=True
Set TheForm = Document.forms("MyFormData")

if isdate(TheForm.DateBought.Value)=False then
msgbox "Error in date", vbokayonly+vbinformation,"Checking Data"
end if

end Function
</Script>

<form action="admin_save_stock.asp" method="post" name="MyFormData" id="MyFormData" onsubmit="validate(); return false;"
language="jscript">
<input name="Make" id="Make" type="text" value="<%= rsTable("Make") %>" size="50" maxlength="50">
<input name="DateBought" id="DateBought" type="text" value="<%= rsTable("DateBought") %>" size="10" maxlength="10">
<input name="Submit" TYPE="Submit" VALUE="Submit">

</form>




"MadMike42" <mike42@ntlworld.com> wrote in message news:yKR0h.13535$76.12222@newsfe5-win.ntli.net...
> This is really starting to annoy me,
> I've got a form, that has some input boxes,
> a example of the code is here:-
>
> <form action="admin_save_stock.asp" method="post" name="MyFormData">
> <input name="Make" type="text" id="MenuText" value=<% response.write rsTable("Make") %> size="50" maxlength="50">
> <input name="DateBought" id="MenuText" type="text" value=<% response.write rsTable("DateBought") %> size="10" maxlength="10">
> </form>
>
> I also have a FUNCTION that checks to make sure the dates etc are correct :-
> But, the code will work as far as giving me the error MSGBOX
> but it still posts to the next page for some reason its
> ignoring the " MyFormData_OnSubmit = False "
>
> Why ?
>
> <Script language="vbscript">
> Function MyFormData_OnSubmit()
> Dim FormOkay
>
> FormOkay=True
>
> if isdate(MyFormData.DateBought.Value)=False then
> msgbox "Error in date", vbokayonly+vbinformation,"Checking Data"
> MyFormData.DateBought.SetFocus
> FormOkay=False
> end if
>
> if FormOkay=False then
> MyFormData_OnSubmit = False
> else
> MyFormData_OnSubmit = True
> end if
>
> end Function
> </Script>
>
> thankls
> Mike.
>
>



MadMike42

2006-10-30, 9:55 pm

That's it !

I changed from .SetFocus to just .Focus and it worked
many thanks
Mike.


"Jon Paal" <Jon nospam Paal @ everywhere dot com> wrote in message
news:12k85e4t06sdp55@corp.supernews.com...
>I don't think there is a "setfocus"
>
> try this
> =============================
>
> <Script language="vbscript">
>
> Function validate()
>
> Dim FormOkay
> FormOkay=True
> Set TheForm = Document.forms("MyFormData")
>
> if isdate(TheForm.DateBought.Value)=False then
> msgbox "Error in date", vbokayonly+vbinformation,"Checking Data"
> end if
>
> end Function
> </Script>
>
> <form action="admin_save_stock.asp" method="post" name="MyFormData"
> id="MyFormData" onsubmit="validate(); return false;" language="jscript">
> <input name="Make" id="Make" type="text" value="<%= rsTable("Make") %>"
> size="50" maxlength="50">
> <input name="DateBought" id="DateBought" type="text" value="<%=
> rsTable("DateBought") %>" size="10" maxlength="10">
> <input name="Submit" TYPE="Submit" VALUE="Submit">
>
> </form>
>
>
>
>
> "MadMike42" <mike42@ntlworld.com> wrote in message
> news:yKR0h.13535$76.12222@newsfe5-win.ntli.net...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com