Newbie - what is my problem?

M

M. Noroozi Eghbali

Hi,

In the asp file, I have a form and a validation function. The message box
opens while validating, but the form action is activated when the validating
is false. I could not find the problem. Any body can help me?

Here is the code:
----------------------------------
<script language="vbscript">
function Validator()
dim Result
Result = true
if len(document.InfoForm.T1.value) < 2 then
msgbox("Please enter your full name")
document.InfoForm.T1.focus
Result = false
end if
Validator = Result
end function
</script>

<form method="POST" name="InfoForm" onsubmit="return Validator()">
<input type="text" name="T1" size="32">
<input type="submit" value="Download" name="B1">
</form>
 
B

Bob Barrows [MVP]

M. Noroozi Eghbali said:
Hi,

In the asp file, I have a form and a validation function. The message
box opens while validating, but the form action is activated when the
validating is false. I could not find the problem. Any body can help
me?

Here is the code:
----------------------------------
<script language="vbscript">
function Validator()
dim Result
Result = true
if len(document.InfoForm.T1.value) < 2 then
msgbox("Please enter your full name")
document.InfoForm.T1.focus
Result = false
end if
Validator = Result
end function
</script>

<form method="POST" name="InfoForm" onsubmit="return Validator()">
<input type="text" name="T1" size="32">
<input type="submit" value="Download" name="B1">
</form>

This is not an asp problem (you could reproduce this problem with a .htm
file could you not?). ASP is server-side code and you are asking about
client-side behavior. Please follow up in the .scripting.vbscript newsgroup,
or one of the groups with "dhtml" in their names.

I need to know how you've determined that validator() is returning False.
You should put a msgbox statement in your function to verify this:

msgbox Result

If it is returning the correct value, then try

window.event.returnValue = False

Bob Barrows
 
M

M. Noroozi Eghbali

Thank you Bob. I set the window.event.returnValue to False and now the
script works fine. I excuse all for sending the message to a wrong group.

Thank you again,
Mehrdad
 
G

G

Take the onsubmit event off of the <form> tag and put an onClick event on
the <input type=submit onClick="return Validator();"> tag.

Also, you should use JavaScript for client-side scripts. VBScript is
limited to IE only.

Glenn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top