Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How can I make two buttons either "invisible" or "visible" based on a text field being either blank or have something typed in it?

Avatar

Level 1

I am trying to make two different buttons either be visible or invisible depending on if a certain text field has something typed into it or not:

1) If the text field is left blank, I want the "SubmitToHR" button visible and the "SubmitToHRccEmp" button to remain invisible.

2) If the text field is filled in, I want the "SubmitToHR" button to be invisible, and the "SubmitToHRccEmp" button to be visible.

With the below code, number 1) works, but 2) does not (I can make the SubmitToHR button invisible, but the SubmitToHRccEmp button does not become visible. Can someone help me find out what I'm doing wrong? Based on everything I've read, I believe the code I have is correct, it just isn't working. Thank you!

form1.Page1.INVISIBLEValidationField::validate - (JavaScript, client)

//Email field validation for cc Employee

if (Page1.EmployeeEmail.rawValue == null)

{

    Page1.SubmitToHR.presence = "visible";

    Page1.SubmitToHRccEmp.presence = "invisible";

}

else if (Page1.EmployeeEmail.rawValue !== null)

{

    Page1.SubmitToHR.presence = "invisible";

    Page1.SubmitToHRccEmp.presence = "visible";

}

2 Replies

Avatar

Level 7

Hi,

This line could likely be your problem.

else if (Page1.EmployeeEmail.rawValue !== null)

Not is != instead of !==

You have one too many equals signs.

Avatar

Level 10

Hi,

Your code looks alright to me, you could remove the whole else condition, so

if (Page1.EmployeeEmail.rawValue == null)

{

    Page1.SubmitToHR.presence = "visible";

    Page1.SubmitToHRccEmp.presence = "invisible";

}

else

{

    Page1.SubmitToHR.presence = "invisible";

    Page1.SubmitToHRccEmp.presence = "visible";

}

But that is not likely to be the problem, is Page1 flowed?  Is SubmitToHRccEmp visible by default?  Maybe if you could share a link to your form.

Regards

Bruce