473,782 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mandatory Form Fields

24 New Member
Hi I have set up a form. What I want to to is with the fields:

Company Postcode
Agency Number
Policy Number

I want these to be mandatory however if someone fills in the company postcode for example the other two fields dont need to be filled in. I just put a line of text in saying: Please ensure either Company Postcode, Agency Number or Policy Number is filled in. but this is not really working well as people are still leaving it blank and they need to able to have the option to fill either or but they need to be mandatory but not, if you know what I mean?

Code below:


[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>

<title>Proforma </title>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">

<script language="javas cript">

function ABC_JScheckForm ( f )
{

var sErrors = "";
var sfocusElements;
var aCheckFields = new Array();

aCheckFields[0] = "txt02_Name_of_ Caller:::Name of Caller";
aCheckFields[1] = "txt03_Type_of_ Caller:::Type of Caller";
aCheckFields[2] = "txt06_Tel_No:: :Tel No";
aCheckFields[3] = "txt11_Comments :::Comments";


// Loop through each field identified as mandatory
for ( var i = 0; i < aCheckFields.le ngth; i++ )
{
var aData = aCheckFields[i].split( /\:\:\:/ );
var oFormElement = eval( "f." + aData[0] );

if ( oFormElement.va lue.match( /^\s*$/ ) )
{
sErrors += aData[1] + "\n";

if ( ! sfocusElements ) { sfocusElements = aData[0]; }

}
}

if ( sErrors )
{
alert( "The following fields are required - \n\n" + sErrors );
eval( "f." + sfocusElements + ".focus()" );
return false;
}

return true;

}

</script>



<FORM name="frmSendMa il" action="http://xxxxxxx/sendmail/" method="POST" onsubmit="retur n ABC_JScheckForm ( this )">

<input type="hidden" name="ctrlSendT oEmailAddress" value="Email@em ail.com=>Profor ma"/>
<input type="hidden" name="ctrlEmail Subject" value="Proforma " />
<input type="hidden" name="ctrlMetho d" value="E-MAIL" />
<input type="hidden" name="ctrlFromE mailAddress" value=""/>
<input type="hidden" name="ctrlRedir ectURL" value="xxxx/xxxxx/submit/" />

<table width="90%" border="0" cellspacing="0" cellpadding="0" bgcolor="8ED1E6 ">
<tr>
<td valign="top" align="left">
<table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="8ED1E6 " align="center">
<tr valign="top" align="left">
<td class="tableBac kLightestBlue" colspan="2" height="27">
<p class="pageHead ">
<p style="color: #CC0000">Fields marked with * are mandatory</p>
</td>
</tr>


<!-- start of form details -->

<TR>
<TD class="tableBac kLgtBlue2">EMAI L TYPE</td>
<td class="tableBac kLgtBlue2"><sel ect size="1" name="sel01_Ema il type">
<option value="Select"> Select</option>
<option value="CALLBACK ">CALLBACK</option>
<option value="INFO REQUEST">INFO REQUEST</option>
</select>
</td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">NAME OF CALLER</td>
<td class="tableBac kLgtBlue2" style="color: #CC0000"><input type="text" name="txt02_Nam e_of_Caller"> *</td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">TYPE OF CALLER</td>
<td class="tableBac kLgtBlue2" style="color: #CC0000"><input type="text" name="txt03_Typ e_of_Caller"> *</td>
</tr>

<TR>
<TD class="tableBac kLightestBlue" colspan="2" height="27" style="color: #CC0000" align="center"> Please ensure either <b>Company Postcode</b>, <b>Agency Number</b> or <b>Policy Number</b> is filled in.</TD>
</TR


<TR>
<TD class="tableBac kLgtBlue2">COMP ANY POSTCODE</td>
<td class="tableBac kLgtBlue2"><inp ut type="text" name="txt04_Com pany_Postcode"> </td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">AGEN CY NUMBER</td>
<td class="tableBac kLgtBlue2"><inp ut type="text" name="txt05_Age ncy_Number"></td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">TELE PHONE NUMBER</td>
<td class="tableBac kLgtBlue2" style="color: #CC0000"><input type="text" name="txt06_Tel _No"> *</td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">FAX NUMBER</td>
<td class="tableBac kLgtBlue2"><inp ut type="text" name="txt07_Fax _No"></td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">POLI CY NUMBER</td>
<td class="tableBac kLgtBlue2"><inp ut type="text" name="txt08_Pol icy_No"></td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">HAND LER</td>
<td class="tableBac kLgtBlue2"><inp ut type="text" name="txt09_han dler"></td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">EMAI L ADDRESS</td>
<td class="tableBac kLgtBlue2"><inp ut type="text" name="txt10_Ema il_Address"></td>
</tr>

<tr>
<td class="tableBac kLgtBlue2">COMM ENTS</td>
<td class="tableBac kLgtBlue2" style="color: #CC0000"><texta rea name="txt11_Com ments" cols="30" rows="4"></textarea> *</td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">TURN AROUND TIMES</td>
<td class="tableBac kLgtBlue2">Turn around time 24 Hours for all callbacks.

</td>
</tr>

<TR>
<TD class="tableBac kLgtBlue2">EMAI L RECIPIENT</td>
<td class="tableBac kLgtBlue2"><p>E mail@email.com</p></td>
</tr>



<tr valign="top" align="left">
<td class="tableBac kLgtBlue2" colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="19">
<tr valign="top" align="left">
<td width="20%">&nb sp;</td>
<td align="center"> &nbsp; </td>
<td align="right" width="20%">
<INPUT TYPE="submit" class="abcButto n" value="SEND MAIL" />
</td>
</tr>
</table>
</td>
</tr>

</table>
</td>

</tr>
</table>

<br><br>

</FORM>
</body>
</html>[/HTML]
Sep 20 '07 #1
2 1693
acoder
16,027 Recognized Expert Moderator MVP
Moved from articles section. Do not post questions there.

Use code tags when posting code:
[CODE=html]
HTML code goes here.
[/code]
Sep 20 '07 #2
gits
5,390 Recognized Expert Moderator Expert
hi ...

you would need to call a function on submit ... have a look at the following example:

Expand|Select|Wrap|Line Numbers
  1. function check_form() {
  2.     // give your fields to check an id (i use id1 ... id3 here)
  3.     // and put it in a map
  4.  
  5.     var field_map = { 'id1': 1, 'id2': 1, 'id3': 1 };
  6.     var val = false;
  7.  
  8.     for (var i in field_map) {
  9.         var field = document.getElementById(i);
  10.  
  11.         if (field.value != '') {
  12.             val = true;
  13.             break;
  14.         }
  15.     }
  16.  
  17.     return val;
  18. }
  19.  
this function returns true, when one of your fields has a value != '' ... otherwise it returns false.

kind regards
Sep 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4721
by: Le Tubs | last post by:
Hi I am wondering if anybody has come accross this problem before, basically I have to validate a xml schema (not the data, this is done at a later stage). The only problem is that there are Mandatory fields, and Optional fields. Thus I don't think a DTD can be used (as a valid xml file can just have the mandatory fields). I have a designed a small validation engine in perl which I'm about to start to code up, but thought I might check...
1
1552
by: AR123 | last post by:
Hi I have set up mandatory form fields but it dosne t seem to be working. Would appreciate it if somone could have a look. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Proforma</title> <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
4
2133
by: plumba | last post by:
Let me explain.... I have a form (most of which you guys have helped me with!!). The initial problem I was having is that it was holding the data in the fields after submit, I resolved this by putting the whole form in a set of <div> tags and the form now collapses after they click submit. Perfect!! But, have set some mandatory fields using java, and I need to it validate the these fields before it collapses the form - otherwise it says...
1
3371
by: AR123 | last post by:
The mandatory form field that is not working is the TYPE OF ILLUSTRATION. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Proforma</title> <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
2
1224
by: bugsbunny12345 | last post by:
i have a form contains 7 fields .. in that if the user enters the value in any one of the field all the remaining 6 fields should be MANDATORY.. if the user didn't enter any value in any field it should not lead to any problem... pls suggest me!!!!!
6
1733
by: Dameon99 | last post by:
Ive been looking through a whole tonne of sites to try to find out how I can make my fields mandatory but havnt been able to find something so far which actually tells me whwta I want to know. Ive tried a couple of code segments but they havnt been working. can anyone tell me how I can make fields in my code mandatory? My attempt at solving this is below: <html> <head> <title>Coals Spiral Brochure Enquiry Form</title>
1
1392
by: ajd335 | last post by:
Hi.. there are some radio buttons,which are mandatory in my site. So how can i find whether they are filled by the user or not ..so that i can respond accordingly.(i.e if all mandatory fields are remaining then , should be a warning display about the same..) <input type="radio" name="small" value="N" autocomplete="off" /> <input type="radio" name="small" value="hidden";value = "required"/> i have used the second one just to mention...
1
1723
pradeepjain
by: pradeepjain | last post by:
Hii , I have a form which has 20-30 textboxes which are mandatory ! is there a way of validating mandatory fields in easier ways by using a single function or some thing like tht ! bcos i will need to check each 20-30 text boxes if value is there or not !! Is there a way to do like define a class=mandatory and when it is found use function on it !
5
3651
by: David Wright | last post by:
Hello All I am using Microsoft Access 2003. I have an input form (Single Form) into which the clerk records appliance details. Some appliance details will never change, for instance the 'Make and Model'. Some details will need to be updated later on, for instance the location of the appliance. When updates are required, the user opens the update form (Single Form). The user is able to cycle through all records of appliances using this...
0
9643
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
9480
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,...
1
10081
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
9946
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
8968
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
7494
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...
0
5378
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.