Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:33:22+00:00 2026-06-10T02:33:22+00:00

I have the following table. In this table I have dynamically added rows of

  • 0

I have the following table. In this table I have dynamically added rows of the following form:

<tr class="conditionalRow">
  <td class="logicalData">
    <select oldvalue="AND" class="logicSelectionMenu">          
      <option value="AND">AND</option>
      <option value="AND (">AND (</option>
      <option value="OR">OR </option>
      <option value="OR (">OR (</option>
      <option value=")">)</option>
    </select>
  </td>
  <td class="fieldData">
    <p>Other Data that you don't need to worry about</p>  
  </td>
  <td class="conditionData">
    <p>Other Data that you don't need to worry about</p>  
  </td>
  <td class="compareData">
    <p>Other Data that you don't need to worry about</p>  
  </td>
  <td>
   <button class="removeConditionButton" type="button"> - </button>
  </td>
</tr>

I use the following jQuery selectors to handle the onchange events:

$(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");

/* -=>  VERY IMPORTANT LINE BELOW!!!  <=- */
//  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
}

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.

  • When the very important line IS NOT 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.

  • When the very important line IS commented out, the JavaScript does not enter the else clause and the content of the following cells are NOT regenerated.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:33:23+00:00Added an answer on June 10, 2026 at 2:33 am

    Thanks to ahren’s observation I have found a fix for my code.

    ahren’s observation:

    “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”

    The Fix:

    $(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");
    
    /* -=>  VERY IMPORTANT LINE BELOW!!!  <=- */
    //  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);
    }
    

    Set the value of oldValue at the end of the function and let oldVal === undefined catch the first pass through the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added following table dynamically using Javascript: <table class=ActionMenu> <tr> <td> <p>Ghanshyam</p> </td>
I have the following problem spanning dynamically added rows to a TableLayout inside a
I have a table where the rows are dynamically removed and added via jQuery.
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
I have the following tweets table: tweet_id user_id text --------------------------------------------------- 1 2 this is
I have the following function. $(function() { $(.sectionHeader:gt(0)).click(function() { $(this).next(.fieldset).slideToggle(fast); }); $(img[alt='minimize']).click(function(e) { $(this).closest(table).next(.fieldset).slideUp(fast);
I currently have the following row in my table: course_data: user_id days <-- This
I have the following dynamically generated table on a page along with other tables
I have the following HTML in a JSP file: <div class=custList> <table class=dataGrid> <c:forEach
I have a HTML table where I am dynamically adding and hiding rows and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.