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

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="JavaScript">
function ValidateForm(){

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

if (Rcv1Field.value != "" && (Refer1Field.value == "" || FRDfield.value
!= "")){

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

Jul 23 '05 #1
2 1859
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.value == ""){
alert('Please Enter a Date Received');
return false;
}
if (Refer1Field.value == "" && FRDfield.value == ""){
alert("Please Enter a Referral Name OR a Resolution Date");
Refer1Field.focus();
return false;
}else if (Refer1Field.value != "" && 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;<input type="text" name="RefNames"><br>
Resolution Date&nbsp;<input type="text" name="ResDate"><br><br>
<input type="button" value="Validate" onclick="ValidateForm()">
</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.value != ""){
if (Refer1Field.value == "" && FRDfield.value == ""){
alert("Please Enter a Referral Name OR a Resolution Date");
Refer1Field.focus();
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
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,...
6
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...
4
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...
0
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...
8
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: ...
2
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...
2
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...
3
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...
2
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...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.