Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks to <em>ahren's</em> observation I have found a fix for my code.</p> <p><em><strong>ahren's</em> observation:</strong></p> <p>"The focus event fires again after selection is changed, and therefore oldVal is updated. Having the alert() removes this focus and prevents it from firing again"</p> <p><strong>The Fix:</strong></p> <pre><code>$(document).ready(function() { $(".logicSelectionMenu").change(function() { var row = $(this).closest("tr"); updateLogicMenu(row); }); /* DON'T USE onfocus event to set the oldValue $(".logicSelectionMenu").focus(function() { $(this).attr("oldValue",$(this).val()); }); */ }); function updateLogicMenu(inRow) { var selectedVal = $(inRow).find(".logicSelectionMenu").attr("value"); var oldVal = $(inRow).find(".logicSelectionMenu").attr("data-oldValue"); /* -=&gt; VERY IMPORTANT LINE BELOW!!! &lt;=- */ // alert("Hi, I cause a time delay"); if (selectedVal == ")") { // clears cell contents if ")" is choosen by user $(inRow).find(".fieldSelectionMenu" ).css("visibility","hidden").html(""); $(inRow).find(".conditionSelectionMenu").css("visibility","hidden").html(""); $(inRow).find(".compareData" ).css("visibility","hidden").html(""); } else if(oldVal == ")" || oldVal === undefined) { // regenerates cell contents when user changes selection from ")" to another alert("regenerating"); $(inRow).find(".fieldSelectionMenu" ).css("visibility","visible").html(getFieldSelectionOptions()); $(inRow).find(".conditionSelectionMenu").css("visibility","visible"); $(inRow).find(".compareSelectionMenu" ).css("visibility","visible"); updateFieldMenu(inRow); // function regenerates the next cell contents // and calls another function // which regenerates the next cell contents, // and chains on and on ... etc } else { ; } // no action is needed,no clearing or regeneration /* SET THE VALUE HERE: */ $(inRow).find(".logicSelectionMenu").attr("data-oldValue",selectedVal); } </code></pre> <p>Set the value of <code>oldValue</code> at the end of the function and let <code>oldVal === undefined</code> catch the first pass through the function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload