Field validation with JS Header

I am working on a web form using JS Header for field validation. I have been tasked to add some optional fields on the form. I created two fields to accomplish these and one is a checkbox field and the other one is a text field. My problem is what should I add on the code below so that if a user enters text on the text field the system either places a checkmark automatically on the checkbox field or prompts the user to place a check mark on the checkbox field. This should work both ways also so that if a user places a check mark on the checkbox field then they get a prompt to enter text on the text field.Any help with this will be highly appreciated.

Heres my current JS Header:

function ValidateFields()

{

/* Check if mandatory fields contains values */

f = document.forms[0];

if (f.username_dt.value == “” ||

f.dept.value == “” ||

f.category.value == “”

)

{

alert(“You must complete all entries marked mandatory: \n\n Then submit this form!”);

f.sub.focus();

}

else

{

f.submitbutton.disabled=true;

f.submit();

}

}

function CannotSave()

{

alert(“You do not have priviledges to modify this information!”);

}

Subject: Field validation with JS Header

Sanjay,

This is just the syntax. Add the following in code in jsheader and call the code when the form is submitted.

If document.forms[0].yrcheckbox[0].checked == true{

alert(“please enter the text field”);

document.forms(0).yrtextfield.focus()

}

if document.forms[0].yrtextfield.value <> “”

{alert(“please select the check box”);

document.forms(0).yrcheckbox.focus()

}