473,698 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation function problem.

I've a function that validate a form field:

<html>
<head>
<script language="JavaS cript">
function CheckFields(For mSubmit,BtnName )
{
if (BtnName!="Canc el")
{
check = true;
if (FormSubmit.Use r_Account.value == ""){
alert ("Username compulsory");
FormSubmit.User _Account.focus( );
return false;
}....

My FORM:
<form action="<?php echo $editFormAction ; ?>" name="formSubmi t"
method="POST"> <!--form action myself-->
....
<input type="submit" name="SubmitBut ton" value="Add"
onClick="CheckF ields(this.form , this.value)">
&nbsp;<input type="submit" name="SubmitBut ton" 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.Subm itButton.name,
but it doesn't work)

Please help.
Jul 20 '05 #1
3 2634
"Bob Bedford" <be******@YouKn owWhatToDohotma il.com> wrote in
news:3f******** **************@ news.sunrise.ch :
<input type="submit" name="SubmitBut ton" value="Add"
onClick="CheckF ields(this.form , this.value)">
&nbsp;<input type="submit" name="SubmitBut ton" 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******@earth link.net> a écrit dans le message de
news:Xn******** *************** ********@130.13 3.1.4...
"Bob Bedford" <be******@YouKn owWhatToDohotma il.com> wrote in
news:3f******** **************@ news.sunrise.ch :
<input type="submit" name="SubmitBut ton" value="Add"
onClick="CheckF ields(this.form , this.value)">
&nbsp;<input type="submit" name="SubmitBut ton" 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_Quick Form.

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
3910
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 adresses and so on. I thought it might be a better way to programm an automated, dynamic form validation that works for all kinds of fields, shows the necessary error messages and highlights the coresponding form fields.
3
2337
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 items missing etc.all working fine... However, when the user logs in I fire off to a stored procedure, at this point, unless the login is successful I can return up to about 8 different error numbers in a string which I then split out into an...
4
10145
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 the validators. The user enters the data, presses OK. My OK button is dynamically generated as well, with some code-behind logic in
2
2086
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 reason we came up with for this was because we had a PageBase base class for all our pages. This base class takes the controls on the child page class and places them onto the form being rendered. It seems that in this process, the rendering of the...
1
3948
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 the same issue. However, none of the suggested fixes solved my particular problem. I tracked down the cause of the problem, which is related to aspx page parser's handling of controls inside html comments. The problem may be quite common and well...
9
4173
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 honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
27
4745
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
1
1939
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 when the user clicks save i.e check that user exists in table, check users password is the same as password in table, check password is valid, check that logged in user is a super user etc etc to get the correct error message. Different forms may or...
2
1481
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. ///////////////////////////////////////////////////////////////////////////////////// function validateForm() { var valid = true; var today = new Date();
13
3597
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 this time (in fact, I don't even know if it totally works, I'm still debugging). However, the first problem is that when an error is encountered, I get my alert box, I press ok and then the form is submitted and the new data is entered into the...
0
8676
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7732
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6522
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
3
2006
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.