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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:55:33+00:00 2026-06-15T17:55:33+00:00

I’m having difficulty making a clickable button in my dynamically generated table that would

  • 0

I’m having difficulty making a clickable button in my dynamically generated table that would send data specific to the table cell that was clicked.

My table is generated and modified whenever the user types into the search box with this AJAX call:

      $(document).ready(function(){
        $("#data").keyup(function () {
            $.ajax({
                type: "POST",
                dataType: "JSON",
                data: "data=" + $("#data").val(),
                url: "search1.php",
                success: function(msg){
                    var output = "";
                    for(var i = 0; i < msg.length; i++) {
                        output += '<tr onmouseover=this.style.backgroundColor="#ffff66"; onmouseout=this.style.backgroundColor="#F0F0F0";>';
                        output += '<td>';
                        if (msg[i].website != ''){ output += '<a href = ' + msg[i].website + ' target = "_blank">' + msg[i].name + '</a></td>';}
                        else output += msg[i].name + '</td>';
                        output += '<td class="description">' + msg[i].description + '</td>';
                        output += '<td><input type="button" onclick=' + submit() + ' value=' + msg[i].id + '></td></tr>'; // Here is where I'd like to put in a clickable button 
                    }
                    $("#content").html(output);
                    $("#myTable").trigger("update");
                }
            });
        });
    });

If I make submit() simply alert("hello") it runs when the page is loaded for every instance of the onclick call to submit(). Could someone please explain to me how to make submit only get called when its button is clicked and not on page load. Thanks in advance.

  • 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-15T17:55:34+00:00Added an answer on June 15, 2026 at 5:55 pm

    You are trying to assign submit() to the button’s onclick, but you are actually calling the function when you generate the string output. It needs to be in quotes inside the string, not concatenated in.

     output += '<td><input type="button" onclick="submit()" value="' + msg[i].id + '"></td></tr>';
     //----------------------------------------^^^^^^^^^^^^
    

    A better strategy would be to leave out the onclick attribute entirely, and use jQuery’s .on() to dynamically assign the method. It is often considered a better practice to bind events dynamically rather than hard-code them into HTML attributes.

    // No onclick attribute in the string:
     output += '<td><input type="button" value="' + msg[i].id + '"></td></tr>';
    
    // And a call to .on() in the $(document).ready()
    $('input[value="'+msg[i]+'"]').on('click', function() {
      submit();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build

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.