I have a series of input field in a from. However I have 3 fields that need to be required if one of them has a value. If all 3 are blank I do not want them to be required. The problem I am having is if I leave the fields blank and sumbit my form its telling me I have a value in one of the fields and that the other 2 are required. My code is below. Can someone help me please. thanks!
<code>
<script language="javascript">
function validatePatientSearchForm()
{
if (document.getElementById('LAST_NAME').value != "" && document.getElementById('FIRST_NAME').value == "" || document.getElementById('BIRTH_DT').value == "")
{
alert("You entered a last name. You must also enter in a first name and date of birth.");
return false; }
if (document.getElementById('LAST_NAME').value == "" || document.getElementById('FIRST_NAME').value == "" && document.getElementById('BIRTH_DT').value != "")
{
alert("You entered a date of birth. You must also enter in a first name and last name.");
return false; }
if (document.getElementById('LAST_NAME').value == "" || document.getElementById('BIRTH_DT').value == "" && document.getElementById('FIRST_NAME').value != "")
{
alert("You entered a first name. You must also enter in a last name and date of birth.");
return false; }
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.
You can go back and change your post to add code tags by clicking the button on your post.
LaTeef Lusk wrote:The problem I am having is if I leave the fields blank and sumbit my form its telling me I have a value in one of the fields and that the other 2 are required.
Which alert message you got? Try to look into that code to check why the condition gets true.
Also, cover OR boolean expression, like