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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:26:13+00:00 2026-06-04T04:26:13+00:00

I need to invoke a function on click of a link in a table

  • 0

I need to invoke a function on click of a link in a table and pass a variable to make a new query to the database.

In practice, I show a table of data in a table of my db. I want to view them in a new page (but only the row selected by me).

How can I send to the server (using jquery) the ID that is in the anchor element id attribute when it is clicked?


ITALIAN VERSION
Io necessito di richiamare una funzione sull’ onclick di un link presente in una tabella e passargli un variabile per effettuare una nuova interrogazione al db.

come posso fare?

In pratica, mostro in una tabella dei dati di una tabella del db. e poi voglio visionarli in una nuova pagina (ma solo la riga scelta da me)

come posso fare per inviare al mio javascript (uso jquery) il valore id selezionato


Here’s my code:

<?php

print("

codice to make a table

<...
< td>< a id=rich".$idrichiesta." href=\"#\" onclick=vediticket(".$idrichiesta.")> vedi link < ./a>

...

efunction vediticket(ID){
$.ajax({
type: "POST",
url: "inc.miapagina.inc.php",
data: "idric="+ID,

success:function(msg){
("#mydiv").html(msg);
}
});
}`e

  • 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-04T04:26:14+00:00Added an answer on June 4, 2026 at 4:26 am

    I really don’t know what all these symbols are in your code. Your code is just messy and hard to read. You need to clean it up. And I don’t think there is a keyword in JavaScript called “efunction”. I also don’t know why you’re putting everything in a PHP print(). That’s harder to maintain.

    Use this for your td’s (and not in PHP print() but you can just us this as regular html and then echo the variables individually with <?php ?> right in the attribute):

    <td><a href="#" id="rich<?php echo $idrichiesta; ?>">Click here</a></td>
    

    And this in your JavaScript file:

    $('td a').click(function() {
        var ID = $(this).attr('id').replace('rich','');
        $.ajax({
            type: "POST",
            url: "inc.miapagina.inc.php",
            data: "idric=" + ID,
            success: function(msg) {
                $("#mydiv").html(msg); // what is #mydiv? you need to change this to the actual element you want the message to be put into
            }
        });
    });​
    

    Also don’t use inline JavaScript (onclick="", etc.) That is bad practice since it gets hard to maintain. Register events programmatically like above, rather than inline instead if you’re going to use jQuery. Registering events programmatically (like above) is Unobtrusive JavaScript.

    I hope this helps.

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

Sidebar

Related Questions

I need to invoke a server side function when an item is picked in
I need to invoke a mapreduce job from java application. I use ToolRunner.run(new Validation(),
I am currently on chart.gsp, I need to invoke a javascript function -filterResult() which
I need to invoke a ColdFusion function(present in a .cfm file) when the user
I have a list of callback functions that I need to invoke when an
I need to execute a function before each def in the controller is invoked
I need to invoke a method without knowing a priori what will the amount
I need to invoke a call from code how can i do it ?
I need to invoke the setter methods of a class using reflection, and the
I need to invoke Selenium from Client Side, so I'm trying to run Selenium

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.