473,325 Members | 2,671 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,325 software developers and data experts.

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="return
checkrequired(this)" etc., checking for required fields and making
sure the agree-to-terms button is checked? Thank you!

<script language="JavaScript" 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(missinginfo);
return false;
}
else {
return true;
}
}
// --->
</script>
<SCRIPT TYPE="text/JavaScript">
<!-- Begin
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea") &&
tempobj.value=='')||(tempobj.type.toString().charA t(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUppe rCase();
alert("Please make sure the "+shortFieldName+" field was properly
completed.");
return false;
}
else
return true;
}
// End -->
</SCRIPT>
Jul 23 '05 #1
2 1842
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="return
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="return
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
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...
7
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,...
1
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...
1
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
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...
23
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...
36
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...
0
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.