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 8219815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:18:23+00:00 2026-06-07T13:18:23+00:00

I have a table below which contains a textbox and next to the textbox

  • 0

I have a table below which contains a textbox and next to the textbox it contains a hyperlink known as “Open Grid”. If the user clicks on this link, it opens up a grid and on this grid it displays number buttons from 3 – 26.

<table id="optionAndAnswer" class="optionAndAnswer">
    <tr class="option">
    <td>1. Option Type:</td>
    <td>
    <div class="box">
        <input type="text" name="gridValues" class="gridTxt maxRow" id="mainGridTxt" readonly="readonly" />
        <span href="#" class="showGrid" id="showGridId">[Open Grid]</span>
    </div>


    <table class="optionTypeTbl">
    <tr>

        <tr><td><input type="button" value="3" id="btn3" name="btn3Name" class="gridBtns gridBtnsOff">

        <input type="button" value="4" id="btn4" name="btn4Name" class="gridBtns gridBtnsOff">
        <input type="button" value="5" id="btn5" name="btn5Name" class="gridBtns gridBtnsOff">
        <input type="button" value="6" id="btn6" name="btn6Name" class="gridBtns gridBtnsOff">

        //...goes all the way to btn26
            </tr>

            </table>

            </td>
    </tr>
</table>

Now the code below is able to trigger one of the grid buttons to state that a grid button is clicked. This code is below:

$('#btn'+gridValues).trigger('click');

Now everything above is fine.

THE PROBLEM:

The issue I have is that a user can add a row containing the same template as the option control on top. But within this option and answer control, the user can change an option type if they wish by clicking on one of the grid buttons in this template. So my question is that how do I write the .trigger() to correctly point to a grid button within this template? If you look at the above code, it users the button’s id, but if you look at code below which does the template, it doesn’t contain an id, it simply just copies the option and control features from above into the template.

Below is the template:

function insertQuestion(form) {    

 var context = $('#optionAndAnswer');

    var $tbody = $('#qandatbl > tbody'); 
    var $tr = $("<tr class='optionAndAnswer' align='center'>");
    var $options = $("<div class='option'>Option Type:<br/></div>");
    var $questionType = '';

    $('.gridTxt', context).each( function() {

    var $this = $(this);
    var $optionsText = $("<input type='text' class='gridTxtRow maxRow' readonly='readonly' />")
    .attr('name',$this.attr('name')+"[]")
    .attr('value',$this.val())
    .appendTo( $options )
    .after("<span href='#' class='showGrid'>[Open Grid]</span>");

    $questionType = $this.val();

    });


    $td.append($options);
    $tbody.append($tr); 

}

UPDATE:

I have created a URL for this application here. Please follow the steps to use the application and then you can see what is happening:

  • Step 1: When you open application, you see a green plus button on the
    page, click on it and it will display a modal window.
  • Step 2: In modal window there is a search bar, type in “AAA” and
    submit search, you will see a bunch of rows appear.
  • Step 3: In the first row, you see under “Option Type” A-D, click on
    the “Add” button within this row, the modal window will close and you
    see in the grey textbox on right hand side that “Option Type” textbox
    equals 4 and it displays the Answer buttons A,B,C and D, this is
    because as you remember the option type for that row was “A-D”.

Now this works fine but it only works for the top option and answer control, follow the steps below:

  • Step 4: Click on the “Add Question” button, it adds a row underneath
    containing the details from the option and answer control on top.
  • Step 5: Within the row you have just added, you see a green plus
    button on left hand side, click on this button and perform the same
    search “AAA” in search box.
  • Step 6: This time select the last row by clicking on its “Add”
    button, the “Option Type” for this row is “A-G” so it should display
    “Answer” buttons A,B,C,D,E,F and G, but it doesn’t do this, it still
    states “A,B,C,D”.

So how do I change the answer buttons display in the option and answer control within one of the appended rows?

The addwindow() function you see in the view source in the application is the function which occurs after the “Add” button is clicked on. The “Add” button is in an included PHP script and the code for this button is below and with it are all the columns you see after you have performed a search in the modal window:

     echo "<table border='1' id='resulttbl'>
      <tr>
      <th class='questionth'>Question</th>
      <th class='optiontypeth'>Option Type</th>
      <th class='noofanswersth'>Number of <br/> Answers</th>
      <th class='answerth'>Answer</th>
      <th class='noofrepliesth'>Number of <br/> Replies</th>
      <th class='noofmarksth'>Number of <br/> Marks</th>
      </tr>";
      foreach ($searchResults as $key=>$question) {
        echo '<tr class="questiontd"><td>'.htmlspecialchars($question).'</td>';
        echo '<td class="optiontypetd">'.htmlspecialchars($searchOption[$key]).'</td>';
        echo '<td class="noofanswerstd">'.htmlspecialchars($searchNoofAnswers[$key]).'</td>';
        echo '<td class="answertd">'.htmlspecialchars($searchAnswer[$key]).'</td>';
        echo '<td class="noofrepliestd">'.htmlspecialchars($searchReply[$key]).'</td>';
        echo '<td class="noofmarkstd">'.htmlspecialchars($searchMarks[$key]).'</td>';
        echo "<td class='addtd'><button type='button' class='add' onclick=\"parent.addwindow('$question','$searchMarks[$key]','$searchNoofAnswers[$key]','$searchOption[$key]','$searchReply[$key]','$searchAnswer[$key]');\">Add</button></td></tr>";
}
      echo "</table>";
  • 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-07T13:18:25+00:00Added an answer on June 7, 2026 at 1:18 pm

    I’m afraid I must be the bearer of bad news. The problem you are having stems from the overall design. Your HTML and javascript really need a bottom-up overhaul with the aim of getting all javascript into a single $(function(){…}) structure, and thus into the same scope. To achieve this you will need to :

    • Attach all event handlers in javascript in favour of the HTML attribute approach (currently hybrid).
    • Purge the iFrame in favour of fetching previous questions via AJAX.

    In the process you will also purge some duplicate click handling (plus button img and its <a>...</a> wrapper).

    Then, you can start to find a solution to your problem :

    • Delegate all event handling associated with the original “Option and answer” block to a container that is common to it and all future “Option and answer” blocks. The common container may be document but preferably something more specific. This appears to be partly achieved already.
    • Ensure that all internal referencing within the original “Option and answer” block works with classes rather than ids. .closest() and .find() will be useful here.
    • On clicking the “+” button, store a reference to the “Option and answer” block (eg. a jQuery object representing its container, discovered relatively). Easiest approach is to store this reference in a variable in the $(function(){...}) scope. (Now you are benefiting from making all those structural changes). The “Add” buttons’ click handler will use this reference to affect the correct “Option and answer” block.
    • On “Add Question”, use jQuery’s .clone(true, true) to make a copy of the original block (then insert the clone into the DOM). If the other fixes have been applied, then all functionality (click handlers) will attach to the clone automatically.

    I work quite quickly but it would still allow 1-2 days for this.

    Here’s how I would organise the javascript.

    $(function() {
        // **********
        // Data area
        // **********
        var $$ = { // reusable static jQuery objects
            'optionTypeTbl': $('#optionTypeTbl'),
            'o_and_a_proto': $("#proto"),
            'o_and_a_extras': $("#extras"),
            'modal': $("#modal")
        },
        $o_and_a_section = null;
    
        // ******************
        // Utility functions
        // ******************
        function trim(str) {
            return str.replace(/(^\s*)|(\s*$)/gi, "") // removes leading and trailing spaces
                .replace(/[ ]{2,}/gi," ") // replaces multiple spaces with one space 
                .replace(/\n +/,"\n"); // Removes spaces after newlines
        }
    
        // ****************
        // Initial actions
        // ****************
        $$.modal.hide();
        $("input.gridBtns").removeClass("gridBtnsOn");
        $("input.answerBtns").removeClass("answerBtnsOn");
        $$.optionTypeTbl.hide();
        // code above makes sure all buttons start in the OFF state (so all button are white).
    
        // **********************************************
        // Handlers for elements inside the main window
        // **********************************************
        $(document).on('click', function() {
            $$.optionTypeTbl.fadeOut('slow');
        });
        $("input.gridBtns", $$.optionTypeTbl).on('click', function() {
            var $this = $(this);
            var $container = $this.closest('.optionAndAnswer');
            $container.find(".gridBtns").removeClass("gridBtnsOn");
            $this.addClass("gridBtnsOn");
            $container.find(".gridTxt").val($this.val());
            //$container.siblings('span[name=gridValues[]]').val($this.val()); // ???
            $container.find('.answerBtns').each(function(index) {
                if (index < Number($this.val())) {
                    $(this).show();
                } else {
                    $(this).hide();
                }
            });
        });
        $$.o_and_a_proto.find(".showGrid").on('click', function(e) {
            var $this = $(this);
            var $container = $this.closest(".optionAndAnswer");
            $("input.gridBtns").removeClass("gridBtnsOn");
            var value = $container.find(".gridTxt").val();
            //$("#btn" + value.replace(/\s/g, '')).addClass("gridBtnsOn"); //???
            $$.optionTypeTbl.appendTo($this.closest("div.box")).show().css({
                left: $this.position().left,
                top: $this.position().top + 20
            });
            e.stopPropagation();
        });
        $$.o_and_a_proto.find(".plusimage").on('click', function() {
            $o_and_a_section = $(this).closest(".optionAndAnswer");
            $$.modal.modal();
        });
        $$.o_and_a_proto.find(".answerBtns").on('click', function() {
            //btnclick(this); // ???
        });
        $("#addQuestionBtn").on('click', function insertQuestion() {
            $$.optionTypeTbl.hide().appendTo(document);//ensure this itinerant table is not cloned
            $$.o_and_a_extras.append($$.o_and_a_proto.clone(true,true).attr('id','')).find("span#plussignmsg").remove();
        });
    
        // **********************************************
        // Handlers for elements inside the modal window
        // **********************************************
        $$.modal.find("#close").on('click', function() {
            $.modal.close();
            return false;
        });
        $$.modal.find("form").on('submit', function() {
            var form = $(this).get(0);
            $.ajax({
                url: 'previousquestions.php',
                data: {
                    'searchQuestion': 1,
                    'questioncontent': trim(form.questioncontent.value)
                },
                type: "get",
                success: function(html) {
                    $("#searchResults").html(html);
                },
                error: function() {
                    alert("Something went wrong");
                }
            });
            return false;
        });
    
        $$.modal.find("#searchResults").on('click', 'button.add', function() {
            var $container = $(this).closest("tr");
            var g = $container.find("optiontypetd").data('g');
            var btn = $container.find("answertd").text();
            $o_and_a_section.find("input.gridTxt").val(g);
            if($o_and_a_section.closest("#detailsBlock").length) { //if is original Options and Answers section
                //do something ???
                //$('#btn'+g).trigger('click'); //???
            }
            $.modal.close();
        });
    });
    

    This works to an extent, but please note that it requires associated changes to the HTML and CSS.

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

Sidebar

Related Questions

I have a user table in my database which contains two columns FirstName and
I have a table T (structure below) which initially contains all-NULL values in an
I have one user table. and second language table which contains language that user
I have a table which contains asp radiobuttonlists (see below) for a survey. Once
I have a table in in which every row contains a form. see below
I have a query as below to find duplicates in my table which contains
I have thousands of html pages which contains below table content ~ <table height=94
I have two tables below. Item Table This Item Table contains ItemId and Total
I have the following listbox below which binds to a database table of image
I have a Generic List object which hold below table as its own value.

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.