Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Make one field required based on another field

Avatar

Former Community Member

I am trying to set a form up, so that when a check box is marked, then the corresponding date field is required.  I set the script language to Javascript and entered this script: 

if

(this.rawValue == "1") (PROPOSALDATE.mandatory = "error")

However, I get an error message stating "syntax error near toekn '!' on line 1, column 20."  There is no ! in this script, so I don't know what it is talking about.  What am I doing wrong?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

The script that executes if the statement is true should be inside curly brackets. So the following in the click event of the checkbox should work:

if (this.rawValue == "1")

{

     PROPOSALDATE.mandatory = "error";

}

else

{

     PROPOSALDATE.mandatory = "disabled";

}

The above is Javascript.

Hope that helps,

Niall

Assure Dynamics

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

The script that executes if the statement is true should be inside curly brackets. So the following in the click event of the checkbox should work:

if (this.rawValue == "1")

{

     PROPOSALDATE.mandatory = "error";

}

else

{

     PROPOSALDATE.mandatory = "disabled";

}

The above is Javascript.

Hope that helps,

Niall

Assure Dynamics

Avatar

Former Community Member

That works perfectly.  Thank you very much for your help.