HI All,
I have a function that validates a form, when the function returns true or
false it still does not submit the form. I am using a <div> tag with text to
submit the form.
I have tried the following ways to make the form submit & validate at the
same time;
1. I have tried the onsubmit function at the top of the form, this seems to
only work with a form button or an image.
2. I have tried to call the function at the href level and this seems to
make the form validate, but the form still submits to a blank page.
I have verified that the function is working with a form button, however I
would like to use a text link with CSS styles around it if possible, couls
someone help me out with the syntax please?
Thanks in advance for your answer
Sean
function validateForm(form) {
var p = form.elements["nameoncard"].value;
var s = form.elements["credit_card"].value;
if (checkGoodCard(s) && p != "")
return true;
else
alert("One or more of your details is invalid or missing, please make sure
that you have entered in your name and or the correct credit card number.");
return false;
}
<form method="post" name="elements" action="test.asp" onsubmit="return
validateForm(this)">
<input type="text" name="credit_card">
<input name="nameoncard" type="text">
<div="sidebar"><ul><li><a
href="javascript:validateForm(this)">continue</a></li></ul>
</form> 4 5761
I think your problem lies with the href
<a href="javascript :validateForm(this)">continue</a>
why not change this to
<a href="javascript :document.elements.submit()">conti nue</a>
"sean" <se********@shopsmart.com.au> wrote in message
news:3f******@dnews.tpgi.com.au... HI All,
I have a function that validates a form, when the function returns true or false it still does not submit the form. I am using a <div> tag with text
to submit the form. I have tried the following ways to make the form submit & validate at the same time;
1. I have tried the onsubmit function at the top of the form, this seems
to only work with a form button or an image. 2. I have tried to call the function at the href level and this seems to make the form validate, but the form still submits to a blank page.
I have verified that the function is working with a form button, however I would like to use a text link with CSS styles around it if possible, couls someone help me out with the syntax please?
Thanks in advance for your answer
Sean
function validateForm(form) {
var p = form.elements["nameoncard"].value;
var s = form.elements["credit_card"].value;
if (checkGoodCard(s) && p != "")
return true;
else
alert("One or more of your details is invalid or missing, please make sure that you have entered in your name and or the correct credit card
number."); return false;
}
<form method="post" name="elements" action="test.asp" onsubmit="return validateForm(this)"> <input type="text" name="credit_card"> <input name="nameoncard" type="text">
<div="sidebar"><ul><li><a href="javascript:validateForm(this)">continue</a></li></ul> </form>
I have tried this, but when I submit the form the function does not work! Do
you have any other Ideas?
"steve stevo" <st***@stevosteve.fsnet.co.uk> wrote in message
news:bo**********@newsg4.svr.pol.co.uk... I think your problem lies with the href
<a href="javascript:validateForm(this)">continue</a>
why not change this to
<a href="javascript:document.elements.submit()">conti nue</a> "sean" <se********@shopsmart.com.au> wrote in message news:3f******@dnews.tpgi.com.au... HI All,
I have a function that validates a form, when the function returns true
or false it still does not submit the form. I am using a <div> tag with
text to submit the form. I have tried the following ways to make the form submit & validate at
the same time;
1. I have tried the onsubmit function at the top of the form, this seems to only work with a form button or an image. 2. I have tried to call the function at the href level and this seems to make the form validate, but the form still submits to a blank page.
I have verified that the function is working with a form button, however
I would like to use a text link with CSS styles around it if possible,
couls someone help me out with the syntax please?
Thanks in advance for your answer
Sean
function validateForm(form) {
var p = form.elements["nameoncard"].value;
var s = form.elements["credit_card"].value;
if (checkGoodCard(s) && p != "")
return true;
else
alert("One or more of your details is invalid or missing, please make
sure that you have entered in your name and or the correct credit card number."); return false;
}
<form method="post" name="elements" action="test.asp" onsubmit="return validateForm(this)"> <input type="text" name="credit_card"> <input name="nameoncard" type="text">
<div="sidebar"><ul><li><a href="javascript:validateForm(this)">continue</a></li></ul> </form>
sean said: <a href="javascript:validateForm(this)">continue</a>
Thanks for asking. We don't get enough opportunities to tell
people not to abuse the "javascript:" protocol this way.
The "javascript:" protocol is used to replace the current contents
of the page with the value of the Javascript expression that
follows the colon. In this case, that's the value returned by
your validateForm() funtion, which apparently displays as blank.
In some cases, people can get away with using the side effect of
evaluating the expression to do something useful in a function,
but submitting a form isn't usually one of those cases.
There's also the problem that the "this" keyword, when used in
an URL like that will NOT be a reference to your form, so your
validation function won't work.
If you must a text link to submit the form, you could use:
<a href="someOtherPageThatApologizesForRequiringJavaS cript.html"
onclick="if(validateForm(document.elements)){docum ent.elements.submit()};return
false"continue</a>
steve stevo wrote: I think your problem lies with the href
<a href="javascript:validateForm(this)">continue</a>
why not change this to
<a href="javascript:document.elements.submit()">conti nue</a>
Because
<a href="javascript:document.forms['elements'].submit()"
onclick="document.forms['elements'].submit(); return false"continue</a>
is, if required, better than that, since it is backed up by W3C recommendations.
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: news |
last post by:
I seriously doubt this is possible...but you never know, so here goes.
Due to bad pre-planning I have a Web page that is VERY table heavy with
a very complicated and delicate setup. Any changes...
|
by: Pat Patterson |
last post by:
I'm having serious issues with a page I'm developing. I just need some
simple help, and was hoping someone might be able to help me out in
here.
I have a form, that consists of 3 pages of...
|
by: Param R. |
last post by:
Hi all, we have a few apps running on server 2003 with .net 1.1 sp1. Simple
web forms with db backend. Websites run over SSL with client certs. Clients
are Windows XP SP2 with all updates and IE....
|
by: whyyyy |
last post by:
The script below works fine if the form is filled out and submitted.
But a (blank) e-mail is sent whenever the page loads, even when the form is
not submitted. I would like to receive the e-mail...
|
by: Chuck Anderson |
last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example
and changing those examples to suit my needs. That said ....
..... I have some select fields in a form I created for a...
| |
by: Advo |
last post by:
Basically, im redesigning a form page on our website.
Currently the user submits the form, it does a few javascript checks
and either submits to the "processstuff.php" page, or gives the user a...
|
by: 0utlawza |
last post by:
Hi Guys
It seems i posted this in the incorrect topic, so i am reposting here.
Please excuse the Newbie question. I am not really a programmer so excuse me if i dont clarify my point...
|
by: Frinavale |
last post by:
I've been trying all morning to cancel a form submit to the server.
I have a JavaScript Object that determines whether or not the page should be submitted to the server depending on whether the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |