So basically i have a form with a action attribute set to another form, it is a survey spread among several pages and using php sessions, now im trying to validate the form with Javascript but it looks imposible because the check boxes all have the same name Q1[](and the array symbol is conflicting with js), the same name is needed for processing the answers with php in the database, i am able to make a form validation of the form below using PHP(if nothing is selected the form wont go to form Q2.php, if more than 1 checkboxe is selected same thing will happen) but can't do it using echo ,like echoing "you must select at least one checkbox" so i try with JS but neither with succes.
Q1.php : -
<head>
-
<title></title>
-
<script>
-
function validation(){
-
if (document.form.Q1.checked == false/* &&
-
document.form.CHKBOX_2.checked == false &&
-
document.form.CHKBOX_3.checked == false*/)
-
{
-
alert ('You didn\'t choose any of the checkboxes!');
-
return false;
-
}
-
else
-
{
-
return true;
-
}
-
}
-
</script>
-
-
</head>
-
-
<body>
-
<form method="post" name="form" action="Q2.php" onsubmit="javascript:validation()">
-
<b>Quel est votre profession ?</b><br />
-
<input type="checkbox" name="Q1[]" value="Artisans, commerçants et chefs d'entreprise"> Artisans, commerçants et chefs d'entreprise<br />
-
<input type="checkbox" name="Q1[]" value="Cadres et professions intellectuelles supérieures"> Cadres et professions intellectuelles supérieures<br />
-
<input type="checkbox" name="Q1[]" value="Agriculteur exploitants"> Agriculteur exploitants<br />
-
<input type="checkbox" name="Q1[]" value="Professions intermédiaires"> Professions intermédiaires<br />
-
<input type="checkbox" name="Q1[]" value="Employés"> Employés<br />
-
<input type="checkbox" name="Q1[]" value="Ouvriers"> Ouvriers<br />
-
<input type="checkbox" name="Q1[]" value="Autres personnes sans activités professionnelle et retraitée"> Autres personnes sans activités professionnelle et retraitée<br />
-
<input type="submit" name="submit_Q1" value="Allez a la Q2">
-
</form>
-
Q2.php : - <?php
-
session_start();
-
session_register('Q1');
-
$_SESSION['Q1'] = $_POST['Q1'];
-
-
$N = count($_POST['Q1']);
-
if(isset($_POST["submit_Q1"]) and $N ==0){
-
header('Location:Q1.php');
-
}
-
if(isset($_POST["submit_Q1"]) and $N >1){
-
header('Location:Q1.php');
-
}
-
-
/*echo $_SESSION['Q1'][0];*/
-
-
-
-
?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
<head>
-
<title></title>
-
</head>
-
<body>
-
<?php
-
-
?>
-
<form action="Q3.php" method="post">
-
<b>Et votre âge s'il vous plait ?</b> <input type="text" name="Q2"><br />
-
Merci beaucoup. Si vous le permettez ...<br />
-
<input type="submit" name="submit_Q2" value="Allez a la Q3">
-
</form>
-
</body>
-
</html>
3 1839 Markus 6,050
Recognized Expert Expert
See getElementsByTa gName().
Also, please in future make the distinction between a PHP problem and a Javascript one.
Mark (moving thread to JS)
yes i thought something like getElementsByTa gName could make it , but how can i use the checked property with getElementsByTa gName ?
acoder 16,027
Recognized Expert Moderator MVP
Loop over the elements returned and then check each one: - if (elems[0].checked) ...
where elems is the collection/array returned.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Phil Powell |
last post by:
Where can I find an online PHP form validator script library to use? I
have tried hacking the one here at work for weeks now and it's getting
more and more impossible to customize, especially now with form
elements that turn out to be arrays that have to be compared with one
another!
I have one form element, languages, a checkbox group. Beside each
checkbox is a dropdown, proficiency (which will become proficiency
alongside languages)....
|
by: TG |
last post by:
I have a validation form that must behave differently based on the results
of a PHP validation check. I have a post command at the top of my form that
calls itself. I don't leave the form when performing the validation check on
the values that were entered into the form, I simply repost the form to
perform the PHP validation. If any of the values that have been entered into
the form are incorrect, I display a warning message on the screen...
|
by: bnp |
last post by:
Hi All,
I am quite new the JavaScript. Basically I am a C++ programmer, but
now I am working on JavaScript since last 5 days.
I have a problem regarding the form validation.
I have created a script that validates the form fields. the validation
procedure is called ONCLICK event of the submit button.
Follwowing is the structure of the validation procedure.
|
by: Hosh |
last post by:
I have a form on a webpage and want to use JavaScript validation for the
form fields.
I have searched the web for form validation scripts and have come up with
scripts that only validate individual fields, such as an "Email Validation
Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they be
joined in some way together to be one script?
I'm a total JavaScript newbie and am completely...
|
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.)
| |
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...
|
by: Rik |
last post by:
Hello guys,
now that I'm that I'm working on my first major 'open' forms (with
uncontrolled users I mean, not a secure backend-interface), I'd like to add
a lot of possibilities to check wether certain fields match certain
criteria, and inform the user in different ways when the data is wrong
(offcourse, this will be checked on posting the data again, but that's
something I've got a lot of experience with).
Now, offcourse it's...
|
by: gweasel |
last post by:
What is the best way to apply a Validation Rule - or rather, where is
the best place to put it? Is there an advantage to putting it on the
field in the table vs setting the validation rule on the form the
control is on?
Basically I have a number of controls in a form that are required, and
to check it I am setting the Validation Rule to "<>"IsNull" so that
when the user tries to tab through/click out of a required area
without entering...
|
by: lucyh3h |
last post by:
Hi,
I am trying to use XMLHttpRequest to do server side validation.
I have several fields on a form and a submit button. The submit button
has an event assocated with it when clicked. The javascript method
will do the form validation for each field one by one.
For each field, an XMLHttpRequst will be made to a PHP file and get
the return, either set an error field (<span>'s innerHTML) or leave it
empty.
Then I'll check the error field...
|
by: ak1dnar |
last post by:
Hi, I got this scripts from this URL
There is Error when i submit the form.
Line: 54
Error: 'document.getElementbyID(....)' is null or not an object
What is this error.
Complete Files
|
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...
| |
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,...
|
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...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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 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...
| |