Expand my Community achievements bar.

Radio Button Script Question

Avatar

Former Community Member
How can I alter this script to leave the field this references visible but only when another button of my choosing is clicked on?



if(RBList.A.rawValue != 1)

{

this.presence = "hidden";

newsubform.presence = "hidden";

}



else if(RBList.A.rawValue == 1)

{

this.presence = "visible";

newsubform.presence = "hidden";

}



As it is now the field disappears when any other buttons are clicked on. I need the field to remain visible but only when a button used for a grand total field is selected. The above script is being used in the calculate event of the subform. I've tried several things but just can't seem to hit the nail on the head.
9 Replies

Avatar

Level 4
I would wrap this radio group in another if statement looking at the second statement and an if statement in the click/change event of the second radio group diong what you want it to.



Tom

Avatar

Former Community Member
Hi Tom,



Thank you. That is what I was thinking but my brain just isn't running at full steam. Lack of sleep and little ones plus a drop dead deadline of this Friday to have this and 5 other forms completed. Would it be too much trouble to provide a visual reference of how the code should look? I've only been doing this about 2 months and although I've been forced to learn a lot I'm still not the best of the best when it comes to scripting. I know what I want to do. I just can't put the pieces completely together yet. Thank you for your help.



Brad

Avatar

Former Community Member
Thanks Tom,



Again your input was helpful but I have only been scripting for 2 months. I put together the above code from information from this blog. I'll try to make this work but it would have been very helpful to have an example if that was possible.



Brad

Avatar

Level 4
Hi Brad,



Looking back at my answer before I don't think it will work as intended, because other fields are controlling the fields you want to keep visible.



What you will need is to find those fields that are controlling the presence limit when they change the presence.



How are you saying you want them to stay visible? A button? A radio group?



I've only been scripting for a month myself.



Tom

Avatar

Former Community Member
Ha ha. Guess we're pretty much in the same scripting boat



Basically I need the numeric field that is in subformA, B, C, D, to remain visible only when either button E or F is checked. That's pretty much it. Functionally the calculations are working with my test running on one filed but from a user standpoint I'm sure they would wonder where the field went when they make the E or F button selection

Avatar

Former Community Member
Really your answer did give me some ideas so it might lead to the answer. I'm looking into using a nested if or else if statement. Basically if I can get it to check the condition button a,b,c,d etc it could work along that line.

Avatar

Former Community Member
Really your answer did give me some ideas so it might lead to the answer. I'm looking into using a nested if or else if statement. Basically if I can get it to check the condition button a,b,c,d etc it could work along that line.



I just found something that might work. Check this out.



if (inpVal != "") {

if (inpVal == "A") {

alert("Thanks for the A.");

} else if (inpVal == "B") {

alert("Thanks for the B.");

} else if (inpVal == "C") {

alert("Thanks for the C.");

} else {

alert("Sorry, wrong letter or case.")

}

} else {

alert("You did not enter anything.")

}

}



I think this is what you were talking about. I found this on this site. Looks like there's some useful info here.



http://www.java2s.com/Code/JavaScript/Language-Basics/DeeplyNestedifelseConstructions.htm

Avatar

Level 4
I'd be tempted to go with a switch statement there instead



switch(varInput)

{

case "A":

// run script for when varInput is the string "A"

break;

case "B":

// run script for when varInput is the string "B"

break;

case "C":

case "D":

// run script for when varInput is the string "C" or "D"

break;

default:

// run script for when varInput does not match an above case

break;

}



Nested ifs work, but can get messy if you have lots of them.



Also, by button do you mean just a plain standard button you press? You could have it set the value of a hidden field, and then look at the value of that field as to whether or not to hide the forms. That way if you looked at that value every time you were changing the presence, you could have it fixed to not change.



Tom

Avatar

Former Community Member
Hey Tom,



Yes I was thinking that too. I've actually tried one but your script looks a little cleaner than mine. Problem is I'm running out of time with this. I have to have it done by tomorrow so I might have to go with a work around for now.



Yes, it is a regular old radio button. The user has 4 choices, each runs there own calculations. The results are used later in the form where they have two more selections. These two selections run their own calculations based on the previous selections. Functionally it is working. The problem is visibility of the field from one of the previous selections.



I've been doing more research into using variables and I believe that is the way to go but I'm hitting the time wall for my initial draft for review. I can probably get around this whole issue by splitting up the form into two pages and using a static subtotal to run my last two equations from for the grand total.



I know using if's and nested if's can get messy. You should see some of the scripts I've been writing to try to get this to work. :-)

I think the scripts would work but I just started using Designer and doing this about 2 months ago. After I hit this deadline I should have about a 2 week break to bone up on Designer and how it works functionally.



Overall though I think you're going in the right direction. Great minds think alike. :-) Thanks for all your input. Brad