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

  • Home
  • SEARCH
  • 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 8467689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:42:57+00:00 2026-06-10T15:42:57+00:00

I am calling a function named edit from an onclick event as follows. <script

  • 0

I am calling a function named edit from an onclick event as follows.

<script type="text/javascript">
  $(document).ready(function () {
    ...

    $.each(data, function (key, val) {
      ...

      var td11 = $('<input type="button" value="Edit" onclick="edit();" />')
        .attr("name",val.Id);

      $(tr2).append(td11);
      $(table1).append(tr2);
    });

    $("#cers").append(table1);

The function is defined outside the $.each loop, inside $(document).ready, as follows

function edit() {
  alert("Id ");
}

When i click on Edit button, Chrome shown error : Uncaught ReferenceError: edit is not defined.

No other errors.

  • 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-10T15:42:59+00:00Added an answer on June 10, 2026 at 3:42 pm

    Probably you have defined edit function not in global scope. It should be defined outside not only $.each loop, but outside $(document).ready and etc. For example this works:

    <!doctype html>
    
    <html>
      <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    
        <script type="text/javascript">
          function func () {
            alert('func');
          }
    
          $(document).ready(function () {
            $('<a href="#" onClick="func();">link</a>').appendTo('#container');
          });
        </script>
      </head>
    
      <body>
        <div id="container"></div>
      </body>
    </html>
    

    But it is better to bind event in javascript, in your case:

    $.each(data, function (key, val) {
      // ... some code
      var td11 = $('<input type="button" value="Edit">')
        .click(edit)
        .attr('name', val.Id);
    
      $(tr2).append(td11);
      $(table1).append(tr2);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
I'm calling a function from an input radio button and have this: onClick=\changeBilling('.$results['id'].', this.value)\
When calling a function in my views/helpers/ file, from my script inside views/scripts/ ,
I'm trying to return a value from (transport) to the calling function, but can't
I am calling a function funcB from funcA . funcB uses several printf statements
I am calling a function in my controller from a button click .... I
I'm calling a php function from my $.ajax call to add a new item
How to get function's name from function's pointer in C? Edit: The real case
Possible Duplicate: Calling a function from a string with the function's name in Python
Why calling a user defined function need the owner name when calling a stored

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.