473,549 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with required fields Javascript

Hello, I have a form that has a few required fields and also an "agree
to terms" checkbox that must be required. I have used Javascripts for
both functions individually, but I need a little help in combining
them. Can someone help me combine these two scripts so they both work
on the same page, with <FORM METHOD=POST onSubmit="retur n
checkrequired(t his)" etc., checking for required fields and making
sure the agree-to-terms button is checked? Thank you!

<script language="JavaS cript" type="text/JavaScript">
<!--//hide script
function checkme() {
missinginfo = "";
if (!document.form .agree.checked) {
missinginfo += "\n - You must agree to the terms";
}
if (missinginfo != "") {
missinginfo ="You must click the box that indicates you agree.";
alert(missingin fo);
return false;
}
else {
return true;
}
}
// --->
</script>
<SCRIPT TYPE="text/JavaScript">
<!-- Begin
function checkrequired(w hich) {
var pass=true;
if (document.image s) {
for (i=0;i<which.le ngth;i++) {
var tempobj=which.e lements[i];
if (tempobj.name.s ubstring(0,8)== "required") {
if (((tempobj.type =="text"||tempo bj.type=="texta rea")&&
tempobj.value== '')||(tempobj.t ype.toString(). charAt(0)=="s"& &
tempobj.selecte dIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName= tempobj.name.su bstring(8,30).t oUpperCase();
alert("Please make sure the "+shortFieldNam e+" field was properly
completed.");
return false;
}
else
return true;
}
// End -->
</SCRIPT>
Jul 23 '05 #1
2 1855
Lee
Cliff R. said:

Hello, I have a form that has a few required fields and also an "agree
to terms" checkbox that must be required. I have used Javascripts for
both functions individually, but I need a little help in combining
them. Can someone help me combine these two scripts so they both work
on the same page, with <FORM METHOD=POST onSubmit="retur n
checkrequired( this)" etc., checking for required fields and making
sure the agree-to-terms button is checked? Thank you!


Change the final "return true" in checkrequired() to "return checkme()".
Indentation would make your code much easier to read.

Jul 23 '05 #2
Thank you so much for your help!

Cliff


On 13 Aug 2004 14:46:21 -0700, Lee <RE************ **@cox.net> wrote:
Cliff R. said:

Hello, I have a form that has a few required fields and also an "agree
to terms" checkbox that must be required. I have used Javascripts for
both functions individually, but I need a little help in combining
them. Can someone help me combine these two scripts so they both work
on the same page, with <FORM METHOD=POST onSubmit="retur n
checkrequired (this)" etc., checking for required fields and making
sure the agree-to-terms button is checked? Thank you!


Change the final "return true" in checkrequired() to "return checkme()".
Indentation would make your code much easier to read.


Jul 23 '05 #3

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

Similar topics

1
2547
by: Spanky | last post by:
I am looking for some help with the following. I have a form with many fields. I have a table in the form that I need to make all the fields within the table required. Basic validation, just need to make sure they are not blank. Here is the kicker.... I have a javascript that adds rows and fields whenever the user clicks a button for...
7
8685
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong, somehow I always end up with error messages and functions not working right. Can someone please help me? I have a form, inside is 1 Text Field...
1
1864
by: Dave | last post by:
Hi, I'm using .NET 1.1 and wondering if I can use RequiredFieldValidators with required fields inside user controls. The page is a type of tabbed panel layout with the divs show/hidden using javascript. Depending on which tab panel is visible upon the submit, I want to execute the appropriate javascript validation. When I submit the...
1
1617
by: SpiderSwamy | last post by:
Hi, I know little bit about asp, I am facing a problem in Validating the ASP Form.. Example: Stud ID: 501242016 FirstName: Ajit LastName: Kar
1
2162
by: dreamlab | last post by:
Hello, Can one of you javascript wizards help out a newbie, please? I’ve got a formHandler that is supposed to check for a good email address and name in the form after clicking the submit link and display a status error message above the form if either the E-mail and/or Name fields are blank, but instead the page does nothing. I think...
23
2763
by: casper christensen | last post by:
Hi I run a directory, where programs are listed based on the number of clicks they have recieved. The program with most clicks are placed on top and so on. Now I would like people to be apple to place a link on there site so people can vote for their program, "ad a click". eg someone clicks the link on some page and it counts +1 click on my...
36
3082
by: aljamala | last post by:
Hi, I keep getting this warning on a page, but I do not know what the problem is...does anyone have an idea about what could be wrong? line 88 column 7 - Warning: missing </formbefore <td> it highlights this line: <form name="frmCurrency" action="" method="post"> Page source....
0
5536
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
1
2871
by: slavisa | last post by:
Hi, i have a form and i use cgi script to email the results back to me. I have a javascript in there already that checks if the required fields are filled when you click submit and if they are not there is a pop up that says these fields are not filled in. When i fill them all in and click submit it works great but it takes me to like...
0
7546
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...
0
7471
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...
0
7740
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. ...
0
7985
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...
1
7503
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...
1
5387
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...
0
5111
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...
0
3517
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...
0
784
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...

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.