473,624 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use one field to validate values in one of two fields

I am using a script to validate a form using the presence of a value in
one field and determine if there is a value in one of two fields. It
is an either/or situation. If the date rcvd field is not "", then
either the ref names has to be filled in OR the res date has to be
filled in. I have tried many combinations of this. Any suggestions
will be greatly appreciated.

<script language="JavaS cript">
function ValidateForm(){

var Rcv1Field = document.form1. DateRcvd
var Refer1Field = document.form1. RefNames
var FRDfield = document.form1. ResDate

if (Rcv1Field.valu e != "" && (Refer1Field.va lue == "" || FRDfield.value
!= "")){

if (Rcv1Field.valu e != "" && Refer1Field.val ue == "" ){
alert("Please Enter a Referral")
Refer1Field.foc us()
return false
}
if (Rcv1Field.valu e != "" && FRDfield.value != ""){
alert("Please Enter a Final Resolution Date")
FRDfield.focus( )
return false
}
}
return true
}
</script>

Jul 23 '05 #1
2 1879
Meredith wrote:
I am using a script to validate a form using the presence of a value in
one field and determine if there is a value in one of two fields. It
is an either/or situation. If the date rcvd field is not "", then
either the ref names has to be filled in OR the res date has to be
filled in. I have tried many combinations of this. Any suggestions
will be greatly appreciated.

<snip>

Does this do what you want? It requires the Date Received field to be
filled in.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled </title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function ValidateForm(){
var Rcv1Field = document.form1. DateRcvd;
var Refer1Field = document.form1. RefNames;
var FRDfield = document.form1. ResDate;
if (Rcv1Field.valu e == ""){
alert('Please Enter a Date Received');
return false;
}
if (Refer1Field.va lue == "" && FRDfield.value == ""){
alert("Please Enter a Referral Name OR a Resolution Date");
Refer1Field.foc us();
return false;
}else if (Refer1Field.va lue != "" && FRDfield.value != ""){
alert("Please Enter ONLY ONE of the following:\n - a Final
Resolution Date\n - a Referral Name");
FRDfield.focus( );
return false;
}
return true;
}
</script>
</head>

<body>
<form name="form1" action="newpage .htm" method="post">
Date Received&nbsp;< input type="text" name="DateRcvd" ><br>
Referral Names&nbsp;<inp ut type="text" name="RefNames" ><br>
Resolution Date&nbsp;<inpu t type="text" name="ResDate"> <br><br>
<input type="button" value="Validate " onclick="Valida teForm()">
</form>
</body>
</html>
Jul 23 '05 #2
Thank you for your assistance....I was able to use the logic of the
suggestion to get the desired result. This is the snippet that I used:

if (Rcv1Field.valu e != ""){
if (Refer1Field.va lue == "" && FRDfield.value == ""){
alert("Please Enter a Referral Name OR a Resolution Date");
Refer1Field.foc us();
return false;
}
}

The Date Rcvd field is not required, however, if it does have a date in
it, either the referral name or resolution date needs to have a value.
Thanks again.

Jul 23 '05 #3

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

Similar topics

7
8690
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 and 2 Password Fields. What I'm looking to do is: - Make sure password fields are equal - Set...
6
2941
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the script created them. It used things like parentnode, insertBefore, appendChildNode,... Any ideas/direction is appreciated.
4
6294
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
0
2943
by: Pato Secruza | last post by:
Hi everyone! I have a really frustrating error and need help. I’m trying to do a function that gets the properties and names of the fields in a MS Access database using ASP. I haven’t programmed in a while so I’m quite lost. Once I have the my database structure I will insert the corresponding fields from a web form but the database is huge and I want to be able to change the database and form without changing the ASP code all the
8
7091
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: BattID VehicleID STDATE STTIME CTC LKO500HF 00000000 10/27/2003 4:13:51 AM 4 LKO500HF 00000000 10/27/2003 5:13:51 AM 5 LKO500HF 00000000 10/27/2003 10:13:51 AM 6 LKO500HF 00000000 10/27/2003 11:13:51 AM 4
2
10414
by: Doslil | last post by:
I am trying to validate the fields in my database.I have already validated the fields to check for not null.Here is what I have written for Numeric and text field. Private Function EENUM() On Error GoTo EENUMErr If IsNull(Me.EmployeesID) Or Me.EmployeesID = "" Or Me.EmployeesID < 0 Then MsgBox "Employee Number Cannot Be Left Blank", vbOKOnly, "Employee Number"
2
2683
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one of my fields. I have a table called "Product" and two of the fields included in this table are "Cost Price" and "Retail Price". I need to create a validation rule so that the Cost Price is always less than the Retail Price. I have tried...
3
3331
by: Claire | last post by:
I have a large record with many enumerated fields. The record is stored in a file and the fields have to be extracted. I validate the data as it's read, but there's so many tests similar to the following that I wondered if it's possible to create a single generic function to perform the validation. Just to keep code size down if nothing else. I'm not that experienced with .net yet so I don't know what's possible. example code reader is...
2
1309
by: Mufasa | last post by:
I have a page where there's some math being done between a couple of fields. They are autopostback so essentially it won't let them go on if certain conditions aren't met. If the person tabs out of one of the fields I do the checks and if they pass I move to the next field. But if don't I want it to stay on the field. I've got all that working except if somebody enters a value and then clicks a different field, since I don't know what...
0
8174
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,...
0
8624
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8478
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
7164
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...
0
4082
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
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
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
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1485
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.