473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Validation function problem.

I've a function that validate a form field:

<html>
<head>
<script language="JavaScript">
function CheckFields(FormSubmit,BtnName)
{
if (BtnName!="Cancel")
{
check = true;
if (FormSubmit.User_Account.value == ""){
alert ("Username compulsory");
FormSubmit.User_Account.focus();
return false;
}....

My FORM:
<form action="<?php echo $editFormAction; ?>" name="formSubmit"
method="POST"> <!--form action myself-->
....
<input type="submit" name="SubmitButton" value="Add"
onClick="CheckFields(this.form, this.value)">
&nbsp;<input type="submit" name="SubmitButton" value="Cancel">

Now, if I click on cancel, I do redirect (with PHP) to a previous page. If I
click on Add, a check is done on the compulsory fields. I would like the
focus on the selected field (the one that isn't right), but the form is
reloaded. How to avoid this ?

I've tried to put the check on the form.OnSubmit (that fires before I submit
the form, and set the buttons input type as "button" instead of "submit"),
instead of the button click (that does submit the form), but I can't
retrieve with button was pushed. (I've tried FormSubmit.SubmitButton.name,
but it doesn't work)

Please help.
Jul 20 '05 #1
3 2628
"Bob Bedford" <be******@YouKnowWhatToDohotmail.com> wrote in
news:3f**********************@news.sunrise.ch:
<input type="submit" name="SubmitButton" value="Add"
onClick="CheckFields(this.form, this.value)">
&nbsp;<input type="submit" name="SubmitButton" value="Cancel">

Now, if I click on cancel, I do redirect (with PHP) to a previous
page. If I click on Add, a check is done on the compulsory fields. I
would like the focus on the selected field (the one that isn't right),
but the form is reloaded. How to avoid this ?


Your event handler needs to *return* the value from CheckFields:
onClick="return Checkfields..."
Jul 20 '05 #2
Thanks Eric...it was that simple !!!

Regards

"Eric Bohlman" <eb******@earthlink.net> a écrit dans le message de
news:Xn*******************************@130.133.1.4 ...
"Bob Bedford" <be******@YouKnowWhatToDohotmail.com> wrote in
news:3f**********************@news.sunrise.ch:
<input type="submit" name="SubmitButton" value="Add"
onClick="CheckFields(this.form, this.value)">
&nbsp;<input type="submit" name="SubmitButton" value="Cancel">

Now, if I click on cancel, I do redirect (with PHP) to a previous
page. If I click on Add, a check is done on the compulsory fields. I
would like the focus on the selected field (the one that isn't right),
but the form is reloaded. How to avoid this ?


Your event handler needs to *return* the value from CheckFields:
onClick="return Checkfields..."

Jul 20 '05 #3
in case you have a lot of forms to implement
and a lot of rules to follow or fields to validate
you shoudl check out PEAR:HTML_QuickForm.

it also supports client-side validation via
auto-generated or customly written javascript
functions.

http://pear.php.net/package/HTML_QuickForm

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
3
by: Rob Meade | last post by:
Hi all, I have a login page which has username and password fields, a login button, and 2 validation controls (one for each field) - currently I have controls to display to the summary if the...
4
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all...
2
by: Fourge | last post by:
Hi, I have run into a very strange scenario. In developing an ASP.NET application on framework version 1.1, I found that certain client-side validation scripts were not being rendered. The...
1
by: Hong Hao | last post by:
Recently, I was trying to modify an existing aspx page when client-side validation on that page stopped working. I searched this group and the web in general and found that other people have had...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
1
by: John Chan | last post by:
Hi, Im doing a maintenance application in ajax and coldfusion at work on IE6 exclusively. I have a save button on each form and i have to do various validations server side and on client side...
2
by: Gobind | last post by:
Hello I have been working on this for quite some time now, and have no clue why my app behaves the way it does. Here is the code snippet that controls this behaviour....
13
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.