I had a problem outline on Fri that I have mostly resolved and revised this post from a question to more of an aid in order to be of aid to someone else in my shoes. I do have 2 questions at the end.
In trying to get the change() function to work with both radio boxes and checkboxes, I spent way too many hours going through the examples posted here and online in order to get my code to work. It turned out to be a confusing syntax exercise as many of the examples used different formats. Just thought I’d send this along to perhaps help someone else out. This format finally worked for me.
For the change function line: where 694=field id of a checkbox
jQuery(document).ready(function($){
$(‘ input[name="item_meta[694][]“] ‘).change(function(){ …
To read the values for field id 778, 694 and a text field…
RADIO var val1 = $(“input[name='item_meta[778]‘]:checked”).val();
CHECKBOX var val2 = $(“input[name='item_meta[694][]‘]:checked”).val();
TEXT var val3 = $(“#field_nameOFyourFIELDKEY”).val();
and the syntax that worked for me on comparing was single quotes:
if (val1 === ‘I want apples.’) { …. }
also, when testing for strings in radio/checkboxes that may have “Saved separate values” I found success when searching for the TEXT of the option and not the saved value.
Hope that helps.
Two questions remain:
1. If a field is “Hidden” conditionally (ie. Hide if x == y AND z != a) ) as mine was, once the conditions are met and the field “shows”, could we capture that boolean succes and use it elsewhere? Maybe to set a value for another field. ie, if (Field is no longer hidden) { val2=10;}
2. Is there a way to get a field to recalculate through js without having to compile the expression in js? I would like to keep the calculations on the front end and easily visible.
You do speak to this in the post http://formidablepro.com/help-desk/if-then-calculation-for-radio-button-selection/ and in http://formidablepro.com/help-desk/cascading-calculations-not-working/ and it appears a simple refresh may not work…
I had set up a js change function to create a 0 or 1 to be used as a multiplier in a calculated field to effectively cancel out a component (or not) and this is done in a change function and involves a click and change of one of the fields used in the calculated expression. Although the values are set correctly, I need to refresh the page, or physically change a value in a field that is used in the expression. It would be great to just refresh the calculated field. Just hoping..
BTW, thanks for a such a robust plugin and invaluable help!
PS.. tried to undo the Private… but it wouldnt take..




September 10, 2012 at 9:35 am
I'm not sure what you're asking, but these sound like advanced javascript questions that fall outside the scope of our support.
September 11, 2012 at 2:55 am
ok, thank you.
September 12, 2012 at 6:01 pm
Just an update. I figured out how to do this and thought I'd share.
To automatically update a calculated field to screen, one of the fields in the equation must be changed on the form.
My equation for a cost "Total" was :
[mem-level]+[add-donation]+[extra-fee]).toFixed(2
Since my scenario had one instance where a change could occur indirectly ( a check box field [693] changed the value of the "extra-fee" field, but the change was done in javascript), the "Total" would not update automatically to the viewer. The saved values were correct, but the Total would not LOOK that way until another field in the calculation was changed. Since my Total, was an amount a customer would be billed, I anticipated a lot of confused and unhappy people, even though the amount sent to paypal etc, would end up being correct.
So I needed a way to refresh the form, or recalculate the Total field to reflect the change that the checkbox instigated.
What ended up working for me, was to add in the checkbox field ([693] to the equation, even though there was no value associated with it to affect the equation. The fact that it was physically clicked/changed, made the Total field recalculate, and ALL of the back-end calculations were brought to the Viewer's screen.
So the working equation now is:
[693] + [mem-level]+[add-donation]+[extra-fee]).toFixed
and the fields update automatically with the correct values.
(On a side note, I had thought that the check box field [693] would add a "1" or a "0" in as a boolean. if this had been the case, I would have subtracted that in this equation in order to get the correct amount, ie [693]-[693]+.... but this worked as is and that was not necessary.
This cost me several days of hair-pulling, so I hope someone else can benefit from this.
Topic closed.