Note that there are some explanatory texts on larger screens.

plurals
  1. POVery Strange JS / jQuery behavior - alert() inclusion/exclusion
    primarykey
    data
    text
    <p>I have the following table. In this table I have dynamically added rows of the following form:</p> <pre><code>&lt;tr class="conditionalRow"&gt; &lt;td class="logicalData"&gt; &lt;select oldvalue="AND" class="logicSelectionMenu"&gt; &lt;option value="AND"&gt;AND&lt;/option&gt; &lt;option value="AND ("&gt;AND (&lt;/option&gt; &lt;option value="OR"&gt;OR &lt;/option&gt; &lt;option value="OR ("&gt;OR (&lt;/option&gt; &lt;option value=")"&gt;)&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td class="fieldData"&gt; &lt;p&gt;Other Data that you don't need to worry about&lt;/p&gt; &lt;/td&gt; &lt;td class="conditionData"&gt; &lt;p&gt;Other Data that you don't need to worry about&lt;/p&gt; &lt;/td&gt; &lt;td class="compareData"&gt; &lt;p&gt;Other Data that you don't need to worry about&lt;/p&gt; &lt;/td&gt; &lt;td&gt; &lt;button class="removeConditionButton" type="button"&gt; - &lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>I use the following jQuery selectors to handle the onchange events:</p> <pre><code>$(document).ready(function() { $(".logicSelectionMenu").change(function() { var row = $(this).closest("tr"); updateLogicMenu(row); }); $(".logicSelectionMenu").focus(function() { $(this).attr("oldValue",$(this).val()); }); }); function updateLogicMenu(inRow) { var selectedVal = $(inRow).find(".logicSelectionMenu").attr("value"); var oldVal = $(inRow).find(".logicSelectionMenu").attr("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 } </code></pre> <p>The problem is that when I select the ")" option from the drop down menu and then select another option. the page does now behave as expected. </p> <ul> <li><p>When the very important line <strong>IS NOT</strong> commented out, both alert boxes pops up saying "I cause a time delay" and "regenerating" and the contents of the following cells get regenerated as expected. </p></li> <li><p>When the very important line <strong>IS</strong> commented out, the JavaScript does not enter the else clause and the content of the following cells are NOT regenerated. </p></li> </ul> <p>What is causing this alert box to cause the page to behave as expected, but it's absence make the page behave unexpectedly? Is it the time delay of the user clicking the OK button? I do not want this alert box on the production page so how do I make the page behave the same way with or without the alert box?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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