473,387 Members | 1,641 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,387 software developers and data experts.

Mandatory Form Fields

24
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="javascript">

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.length; i++ )
{
var aData = aCheckFields[i].split( /\:\:\:/ );
var oFormElement = eval( "f." + aData[0] );

if ( oFormElement.value.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="frmSendMail" action="http://xxxxxxx/sendmail/" method="POST" onsubmit="return ABC_JScheckForm( this )">

<input type="hidden" name="ctrlSendToEmailAddress" value="Email@email.com=>Proforma"/>
<input type="hidden" name="ctrlEmailSubject" value="Proforma" />
<input type="hidden" name="ctrlMethod" value="E-MAIL" />
<input type="hidden" name="ctrlFromEmailAddress" value=""/>
<input type="hidden" name="ctrlRedirectURL" 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="tableBackLightestBlue" 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="tableBackLgtBlue2">EMAIL TYPE</td>
<td class="tableBackLgtBlue2"><select size="1" name="sel01_Email type">
<option value="Select">Select</option>
<option value="CALLBACK">CALLBACK</option>
<option value="INFO REQUEST">INFO REQUEST</option>
</select>
</td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">NAME OF CALLER</td>
<td class="tableBackLgtBlue2" style="color: #CC0000"><input type="text" name="txt02_Name_of_Caller"> *</td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">TYPE OF CALLER</td>
<td class="tableBackLgtBlue2" style="color: #CC0000"><input type="text" name="txt03_Type_of_Caller"> *</td>
</tr>

<TR>
<TD class="tableBackLightestBlue" 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="tableBackLgtBlue2">COMPANY POSTCODE</td>
<td class="tableBackLgtBlue2"><input type="text" name="txt04_Company_Postcode"></td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">AGENCY NUMBER</td>
<td class="tableBackLgtBlue2"><input type="text" name="txt05_Agency_Number"></td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">TELEPHONE NUMBER</td>
<td class="tableBackLgtBlue2" style="color: #CC0000"><input type="text" name="txt06_Tel_No"> *</td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">FAX NUMBER</td>
<td class="tableBackLgtBlue2"><input type="text" name="txt07_Fax_No"></td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">POLICY NUMBER</td>
<td class="tableBackLgtBlue2"><input type="text" name="txt08_Policy_No"></td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">HANDLER</td>
<td class="tableBackLgtBlue2"><input type="text" name="txt09_handler"></td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">EMAIL ADDRESS</td>
<td class="tableBackLgtBlue2"><input type="text" name="txt10_Email_Address"></td>
</tr>

<tr>
<td class="tableBackLgtBlue2">COMMENTS</td>
<td class="tableBackLgtBlue2" style="color: #CC0000"><textarea name="txt11_Comments" cols="30" rows="4"></textarea> *</td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">TURNAROUND TIMES</td>
<td class="tableBackLgtBlue2">Turn around time 24 Hours for all callbacks.

</td>
</tr>

<TR>
<TD class="tableBackLgtBlue2">EMAIL RECIPIENT</td>
<td class="tableBackLgtBlue2"><p>Email@email.com</p></td>
</tr>



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

</table>
</td>

</tr>
</table>

<br><br>

</FORM>
</body>
</html>[/HTML]
Sep 20 '07 #1
2 1669
acoder
16,027 Expert Mod 8TB
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 Expert Mod 4TB
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
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...
1
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> ...
4
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...
1
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...
2
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 ...
6
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...
1
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...
1
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.