Validate that a button was clicked

N

news.telkomsa.net

Hi,

I have been trying to ensure that a button is clicked to submit a form. I
have a form with a various fields and a button with a validation script but
the user can press enter on any one of the text input fields, and the form
submits to the "action" page without running the validation.

Could someone give me a pointer?

Thanks
Antony
 
J

JayB

news.telkomsa.net said:
Hi,

I have been trying to ensure that a button is clicked to submit a form. I
have a form with a various fields and a button with a validation script but
the user can press enter on any one of the text input fields, and the form
submits to the "action" page without running the validation.

Could someone give me a pointer?

Does the button need to be clicked for a reason other than validation?

I don't know what language you're using but here's some simple ASP that will
work whether the button is clicked or the enter key is depressed.

<body>

<%
if request.form("submit") = "go" then
'ENTER VALIDATION CODE HERE
end if
%>

<form action="text.asp" method="post">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="go">
</form>

</body>
 
A

Antony Futter

No the button need only be clicked for validation. I am using asp and
vbscript for the validation, but I want to pop-up message boxes with errors
prior to submitting the form.

I suppose that I am looking for a way to ignore the enter key or stop the
enter key from submitting the form.

Regards,
Antony
 
S

SpaceGirl

Antony said:
No the button need only be clicked for validation. I am using asp and
vbscript for the validation, but I want to pop-up message boxes with errors
prior to submitting the form.

I suppose that I am looking for a way to ignore the enter key or stop the
enter key from submitting the form.

Regards,
Antony


I

form


Does the button need to be clicked for a reason other than validation?

I don't know what language you're using but here's some simple ASP that
will

work whether the button is clicked or the enter key is depressed.

<body>

<%
if request.form("submit") = "go" then
'ENTER VALIDATION CODE HERE
end if
%>

<form action="text.asp" method="post">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="go">
</form>

</body>

<script type="text/javascript">

validateMe () {

if (form1.something.value) == "" {

alert("you must complete all items");

}

if (form.something.value) != ""

form1.submit;

}

}

</script>

....


<form action="text.asp" onsubmit="validateMe();">

<form item />

</form>

....

--


x theSpaceGirl (miranda)

# lead designer @ http://www.dhnewmedia.com #
# remove NO SPAM to email, or use form on website #
 
T

Toby Inkster

news.telkomsa.net said:
I have a form with a various fields and a button with a validation
script but the user can press enter on any one of the text input fields,
and the form submits to the "action" page without running the validation.

How are you running the validation script?

<input type="submit" onclick="blah">?

If so, change it to:

<input type="submit">

and then change your <form> element to:

<form onsubmit="blah">

Ought to work.
 
A

Antony Futter

Hi,

I have tried all the various things that people have suggested, but I must
be doind something really silly. I have posted the page to
www.asf.co.za/test/input.asp which then pops up the errors, but continues to
post to the next page, irrelavent of whether or not the button was
clicked/pressed.

Please could someone help?

Thanks
Antony
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top