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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:08:41+00:00 2026-06-07T06:08:41+00:00

I hav a php code where it displays buttons from A-Z: <table id=optionAndAnswer class=optionAndAnswer>

  • 0

I hav a php code where it displays buttons from A-Z:

  <table id="optionAndAnswer" class="optionAndAnswer">
    <tr class="answer">
    <td>3. Answer</td>
    <td>
        <?php
            $a = range("A","Z");
        ?>

        <table id="answerSection">
            <tr>

        <?php
            $i = 1;
            foreach($a as $key => $val){
                if($i%7 == 1) echo"<tr><td>";
                echo"<input type=\"button\" onclick=\"btnclick(this);\" value=\"$val\" id=\"answer".$val."\" name=\"answer".$val."Name\" class=\"answerBtns answers answerBtnsOff\">";      
                if($i%7 == 0) echo"</td></tr>";
                $i++;
            }
        ?>

...

What I am trying to do is create a template for the above code in jquery so that if the user wants to add these buttons into a block, then jquery can be used to add these buttons in a block, exactly like a template.

Below is jquery code:

var $this, i=0, $row, $cell;
$('#optionAndAnswer .answers').each(function() {
    $this = $(this);
    if(i%7 == 0) {
        $row = $("<tr/>").appendTo($answer);
        $cell = $("<td/>").appendTo($row);
    }
    var $newBtn = $("<input class='answerBtnsRow answers' type='button' style='display:%s;' onclick='btnclick(this);' />".replace('%s',$this.is(':visible')?'inline-block':'none')).attr('name', $this.attr('name')).attr('value', $this.val()).attr('class', $this.attr('class'));


    $newBtn.appendTo($cell);

    i++;
});

Now this works fine but I have one issue. If you look at the php code, each button has its own id, in my jquery code, each buttons does not have its own id. In my jquery code I want each button to have the same id as their counterparts in php code except only difference is that I want the jquery button id’s to end with “Row”. E.g. if id for button F in php is #answerF, then I want button F in jquery to have id #answerFRow.

My question is that is this possible? Will this code be able to retrieve the buttons id from php code if I put it in jquery code:

.attr('id', $this.attr('id'))

And how do I insert the word “Row” at the end?

  • 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-07T06:08:41+00:00Added an answer on June 7, 2026 at 6:08 am
    .attr('id', $this.attr('id')+'Row')
    

    PHP just generates text, HTML, which the browser reads, and then renders. So, if the PHP code writes the IDs, then jQuery can read them.

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

Sidebar

Related Questions

Can we create an object of a class inside another class in php?I hav
I hav a table with following fields public class ActivationCode { public virtual int
I hav been going over some old hw assignments from a class last semester.
everyone i hav written some code to read images from the Database in C#.net,
i hav an html file which displays table view ,how to load this on
hi i hav a code like this in the end i m getting error
I hav a table with several fields. One field is date_assigned and the other
How can i get the nth row position from table without using limit ?
i hav a piece of code in which i have been comparing 2D and
I hav a code where Include method contains lowerd name of navigation property (Include(descriptions)

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.