• Resolved davepurchaser

    (@davepurchaser)


    I have a form where a user is able to hit a button to show a dropdown menu. If they hit a different button, the first dropdown menu is hidden and a different one appears. I have different buttons that each use this logic.

    jQuery(‘.dropdown1’).show();
    jQuery(‘.dropdown2’).hide();
    jQuery(‘.dropdown3’).hide();

    etc.. This allows the user to browse one dropdown at a time by hitting a different button.

    The user is able to browse the dropdowns and eventually choose one of the items and continue to the next page.

    Now later in the form, I want to output the last item they selected in those dropdowns by using something like:

    jQuery(‘#result’).html(‘You selected ‘+LAST FIELD NAME SELECTED’);
    })()

    Note where it says “LAST FIELD NAME SELECTED” is where I am stuck. I don’t know how to reference the last field when

    a.) They fields don’t seem to be logically grouped together

    b.) The user may pick several different items from several dropdowns. How do I tell it to pick just the last one?

    Sorry if this is a bit of a complex question. Can I use a fieldset or div container for this?

    • This topic was modified 8 years, 2 months ago by davepurchaser.
Viewing 10 replies - 16 through 25 (of 25 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    I’m sorry, my mistake, the correct one is:

    prec((function(){
    var values = [fieldname2,fieldname6,fieldname73, fieldname74],
    total = 0,
    counter = 0;
    for(var i in values)
    {
    if(values[i]) counter++;
    total += values[i];
    }
    setTimeout(function(){jQuery('[id*="fieldname'+'4_"]').change();},500);
    return (counter)?total/counter:0;
    })(),1)

    Best regards.

    flagging this thread as interesting

    • This reply was modified 8 years, 2 months ago by chadtesting.
    • This reply was modified 8 years, 2 months ago by chadtesting.
    Thread Starter davepurchaser

    (@davepurchaser)

    Well that did solve the issue of it freezing my window. However, it does not force fieldname4 to dynamically update the onchange function, even if I turn dynamic calculations back on. I still have to trigger it manually.

    My best guess is that it has something to do with the fact that fieldname4 (average calculation) is a calculated field whereas the onchange function is an HTML Content field.

    Plugin Author codepeople

    (@codepeople)

    Hello,

    It is not working because you have removed the fieldname4 field from the list of fields in the piece of code:

    <script>jQuery(document).on('change', '[id*="fieldname40_"],[id*="fieldname41_"],[id*="fieldname76_"],[id*="fieldname104_"],[id*="fieldname99_"]', function(){jQuery('#avgs').html('You selected '+jQuery(this).val()+' at '+jQuery('[id*="fieldname4_"]').val()+'%');return true;});</script>

    The correct would be:

    <script>jQuery(document).on('change', '[id*="fieldname40_"],[id*="fieldname41_"],[id*="fieldname76_"],[id*="fieldname104_"],[id*="fieldname99_"],[id*="fieldname4_"]', function(){jQuery('#avgs').html('You selected '+jQuery(this).val()+' at '+jQuery('[id*="fieldname4_"]').val()+'%');return true;});</script>

    I’m sorry, but I cannot help you if you modify multiple pieces of code at same time.

    Best regards.

    Thread Starter davepurchaser

    (@davepurchaser)

    I swear I’m not trolling you and I really do appreciate this, and please don’t kill me but… when I add fieldname4 to my list of fields to be evaluated, it returns

    “You selected” fieldname4 “at” fielname4’%”

    By self-evaluating it correctly calculates, but ends up calculating itself last.

    Thread Starter davepurchaser

    (@davepurchaser)

    Hi, I think I figured out a better way to do it by splitting up these two calculations and using an HTML Output field for each. I am not sure how to format them so they look like a complete sentence but at least the logic works now.

    Thanks so much for your time and energy. You helped me a lot.

    • This reply was modified 8 years, 2 months ago by davepurchaser.
    Plugin Author codepeople

    (@codepeople)

    Yes, you are right if you set the “fieldname4” field in the list, its value would be inserted in both places.

    The solution would be:

    A) Modify the <div id="avgs"></div> as:

    <div>You selected <span id="part_a"></span> at <span id="part_b"></span>%</div>

    B) Modify the code in the previous tickets as follows:

    <script>jQuery(document).on('change', '[id*="fieldname40_"],[id*="fieldname41_"],[id*="fieldname76_"],[id*="fieldname104_"],[id*="fieldname99_"]', function(){jQuery('#part_a').html(jQuery(this).val()});</script>

    C) and finally, modify the equation as follows:

    (function(){
    var values = [fieldname2,fieldname6,fieldname73, fieldname74],
    total = 0,
    counter = 0;
    for(var i in values)
    {
    if(values[i]) counter++;
    total += values[i];
    }
    var result = PREC((counter)?total/counter:0, 1);
    jQuery('#part_b').html(result);
    return result;
    })()

    and that’s all.

    If you need additional help to implement your project, you should contact me through my personal website to requesting a custom coding service:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter davepurchaser

    (@davepurchaser)

    I think that this will work but there’s something wrong with the syntax of one of the HTML fields. When I load my form, the ‘next’ button doesn’t display. Also, the ‘div’ value appears as text in my field. That usually means there’s something off.

    My hunch it is the <script> ticket.

    Div HTML field showing text

    How my form looks when loaded

    Plugin Author codepeople

    (@codepeople)

    Hello,

    In the piece of code I sent you in a previous ticket I have omitted a parenthesis:

    <script>jQuery(document).on('change', '[id*="fieldname40_"],[id*="fieldname41_"],[id*="fieldname76_"],[id*="fieldname104_"],[id*="fieldname99_"]', function(){jQuery('#part_a').html(jQuery(this).val());});</script>

    Best regards.

    Thread Starter davepurchaser

    (@davepurchaser)

    You’re awesome, thanks so much for your time. All works perfectly.

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘Question about referencing last button pressed on a page’ is closed to new replies.