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.

Selecting multiple checkboxes...Please Help!!!

Avatar

Level 4

I am having an issue I have multiple checkboxes - once the checkboxes are selected, I would like some information to appear in a field and if checkbox is deselected I would like the text to disappear.

My major problem is if all the checkboxes are selected at one time and the information appears in the textbox only one line of text will appear at once and I would also like for text to appear on separate lines and not on the same line.

This is what I am working with now:

if

(RadioButtonList4.rawValue == true)

TextField.rawValue

= "This is a value set using a script.";

else

TextField1.rawValue

= "";

Please Help

Tammi

17 Replies

Avatar

Level 2

Here is a javascript code that will make items visible and invisible

// if( this.rawValue == 0 )
// {
//IR1.presence = "hidden";
//IR2.presence = "hidden";
//}
//else
//{
//IR1.presence = "visible";
//IR2.presence = "visible";
//}

(Just remove the //)

Go to this link and look at page 5 and 6 for an example of Controlling the visibility of an UI element

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b01c6b40-ce0f-2c10-e49f-8a54be4d...

Let me know if I can help you any further.  I am learning myself.

Avatar

Level 2

Here is a pdf where once the box is checked text appears.

Avatar

Level 4

Thank you, I have been able to get that far. My problem is having multiple checkboxes and the customer has the option of selecting one or all of the check boxes . If all the check boxes are selected I need for the text to be seen all at once in the field (some of the information will be more than 1 line that is why I am wondering if it is possible to add a carriage return in the script).

thanks

Avatar

Level 2

Can you share your .pdf example if you have one?  I would like to see how you are displaying the text.  Seeing if can just wrap multiple text fields or something.

Avatar

Level 4

I am about to tackle a situation similar to this, but not the same, so I thought I'd post it in this thread. If someone considers this a cross posting, I will gladly start a new thread, but I think the solution to the original poster's question will be very applicable to me.

I want to make a button appear (just like the text box appears in the original post), but only after the user has entered text into all (say, 3 of 3) text fields (sort of like the checkboxes previously mentioned).

Thanks!

Graham

Avatar

Level 4

Hi Graham

For your query I think that you will need to enter some code into the exit event of each of your text fields so that if they are input in a random order by the user the button would fire up in any case.

You should initially set your button to hidden and then the code would be something like this

if ((subform1.textfield1 != null) && (subform1.textfield2 != null) && (subform1.textfield3 != null )) {

Subform1.button1.presence = "visible"

}

else {

Subform1.button1.presence = "hidden"

}

Remeber that null and blank spaces are different so if you do not want the button to fire up if a blank space is input into the text field you will have to do similar code, where "" = blank space.

Something like that should work but if you are having probs then send me the form at djl64@st-andrews.ac.uk and I will have a look.

Hope this helps

Avatar

Former Community Member

In Javascript you need a \n which signifies a newline character.

I assume everything else is working as you want.

Paul

Avatar

Level 4

Classification: UNCLASSIFIED

Caveats: NONE

Paul thanks so much for answering my question...

I tried the /n and it is not working. I have attached an example. (customer has the option of selecting 1 checkbox or all the checkboxes)

Avatar

Level 4

Humm... did you make the Textfield multiline? (Sry but the easiest solutions often are overseen.)

Okey I try to get what you want. I hope I got you right and didn't completly missunderstand you...

Let's assume there are 4 checkboxes.

Okey so the user has 5 options. He can choose each of the checkboxes and NO more or he can choose them all...

choosing 2 out of 4 is not possible.

javascript:

if (this.rawValue == 1 && (checkbox1.rawValue == 1 || checkbox3.rawValue == 1 || checkbox4.rawValue == 1))

// will select everything when more then one checkbox is selected... this one only goes for checkbox 2 the other are nearly the same though!!!

{

     checkbox1.rawValue = 1;

     checkbox2.rawValue = 1;

     checkbox3.rawValue = 1;

     checkbox4.rawValue = 1;

}


if (this.rawValue == 0) // will deselect everything if one checkbox is deselected...

{

     checkbox1.rawValue = 0;

     checkbox2.rawValue = 0;

     checkbox3.rawValue = 0;

     checkbox4.rawValue = 0;

}

Then you create a Textfield (where you normally input things) and put on the calculate event:

if (checkbox1.rawValue == 1 || checkbox2.rawValue == 1 || checkbox3.rawValue == 1 || checkbox4.rawValue == 1)

// will show up if one checkbox is checked. If you want it only to show up if all checkboxes are checked use && instead of ||

{

this.presence = "visible";
}
else
{
this.presence = "invisible";
}




if (checkbox1.rawValue == 1 && checkbox2 == 0)
{this.rawValue = "only checkbox1 is selected";}
if (checkbox2.rawValue == 1 && checkbox1.rawValue == 0)
{this.rawValue = "only checkbox2 is selected";}
if (checkbox3.rawValue == 1 && checkbox1.rawValue == 0)
{this.rawValue = "only checkbox2 is selected";}

if (checkbox4.rawValue == 1 && checkbox1.rawValue == 0)
{this.rawValue = "only checkbox2 is selected";}


//what will appear if it is only a single checkbox that is selected


if (checkbox1.rawValue == 1 && checkbox2.rawValue == 1) //don't need the others since it is just one or all

{this.rawValue = "all checkboxes are selected \ncheck1 \ncheck2 \ncheck3 \ncheck4"}

The thing is, I don't think you can easily input data in static "text"fields. Since you already know how to show and hide you can do that one on your own I think ^^

If I missunderstood you and you just want to add/change the text by the checkboxes that are selected plz say so.

If I got you totally wrong and you just have let's say 10 checkboxes which can be selected and deselected and each one will provide a textfield with data, I can make you a little script for the calculate event...

Just tell me how many checkboxes they are... could get much to write (especially if they are more checkboxes) but I've got a script that will create even long scripts really fast

Avatar

Level 4

Classification: UNCLASSIFIED

Caveats: NONE

Thanks...the customer has the option of selecting 1 or all the checkboxes. My issue is that I can only get one statement to show at a time and if possible I would like each statement to show on a separate line.

I am attaching an example.

Thanks again for your help!

Avatar

Former Community Member

There is no attachment here ...did you forget to attach it?

Paul

Avatar

Level 4

Classification: UNCLASSIFIED

Caveats: NONE

Avatar

Level 4

This is the example

Keeping in my that I would like all the statements to appear if the checkboxes are selected and to appear on a separate line if possible.

Thanks again

Avatar

Former Community Member

You were close .....here is a modified example. Going down your path you would empty the field each time a checkbox was unchecked. Have a look at my way where I rebuild the string each time a check box is changed. Look at the Calculate event of TextField2 for the code.

Paul

Avatar

Level 4

Paul,

I'm just learning scripting (and LC for that matter), and am just looking at code.

On my machine, the first box checked using the first method results in the first and only the first text entry beginning with the word "null". Why is that, and how would you get rid of it?

Graham

Avatar

Level 4

I see that putting the space in between the "" in the statement

this.rawValue = " "

...is what determines if there is the word "null" in the textfield when the first box is checked. But this causes the first entry to begin with a space, messing up the design quality of the final product. Is there some way to get rid of that space without getting the null word in there?

Graham

Avatar

Level 4

Paul, you are awesome!

Thanks a bunch!!!