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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:26:06+00:00 2026-05-16T17:26:06+00:00

I think I may be missing something or haven’t grasped a fundamental of jQuery.

  • 0

I think I may be missing something or haven’t grasped a fundamental of jQuery. I have searched for hours but yet to find an answer to my question.

I’ve got an old website that I’m upgrading to use jQuery and many of the links call a JavaScript onClick call that passes multiple parameters, as per the example below:

<a href="#" onclick="displayData('Book Title', 'ISBN', 'dateOfPublishing', 'Price');">View Details</a>

The problem is that I’ve updated the old displayData function with various jQuery code and the displayData function is within the

$(document).ready(function() { 
});

code, and this seems to prevent the function displayData being called using the onClick as it says object expected. I’ve moved the displayData function out from the $(document).ready() but by doing so, this has prevented references to other functions within the $(document).ready() code being referenced.

A cut down example of what I have is below:

<script>
  $(document).ready(function() {
    function displayData(title, isbn, dt, price) {
      // there's a call to jQuery AJAX here
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "WebServices/BookService.asmx/GetBookReviews",
            data: "{isbn: '" + isbn + "'}",
            dataType: "json",
            success: function(msg) {
                DisplayReviews(msg.d);
            }
        });
      return false;
    }

    function DisplayReviews(data) {
       // data normally formatted here and passed to formattedData variable
       var formattedData = FormatData(data);
       $('#reviewScreen').html(formattedData);
    }

    function FormatData(data) {
      // function reformats data... code removed for space..
      return data;
    }


  });
</script>


<table>
  <tr><td><a href="#" class="reviewLink" onclick="displayData('Book Title', '1234141HABJA1', '2010-01-12', '$15.99');">View Reviews</a></td><td>Book Title</td></tr>
  <tr><td><a href="#" class="reviewLink" onclick="displayData('Book TItle 2', '516AHGN1515', '1999-05-08', '$25.00');">View Reviews</a></td><td>Book Title 2</td></tr>
</table>

What I’d like to do is to be able to remove the onclick="displayData();" within the link and instead us a jQuery click reference, something like

$('a.reviewLink').click(function() {
  displayData(parameters go here....);
});

I just don’t know how I’d pass the parameters to the function from the link as they would not longer be in the HTML onclick attribute.

If I continue to use the onclick attribute in the link, and move the displayData(params) out of the $(document).ready() code block, it works fine, but the moment I try and reference any of the other functions within the $(document).ready() code block I get the dreaded object expected error with the other functions such as DisplayReviews(param).

I don’t know if this makes any sense…. sorry if it’s confusing, I’m not the worlds best programmer and don’t know all the terminology necessarily, so have tried as best I can to explain. I hope you can help.

Many thanks

  • 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-05-16T17:26:06+00:00Added an answer on May 16, 2026 at 5:26 pm

    The init code should go into the .ready(), not your library functions, those can be defined in a seperate .js file.

    <script src="yourFunctions.js"></script>
    <script>
        $(document).ready(function(){
    
             $('a.reviewLink').click(function() {
                 displayData(parameters go here....); // in yourFunctions.js
             });
    
        });
    </script>
    

    An alternative to passing inline parameters without using inline javascript, is to use HTML5’s ‘data-‘ attribute on tags. You can use it in xhtml, html etc as well and it just works.

    html:

    <div data-name="Jack" data-lastname="black">My name is</div>
    

    jquery:

     $('div').click(function(){
          alert($(this).attr('data-name') + ' ' + $(this).attr('data-lastname'));
     });
    

    Note: You HAVE to use either jQuery’s .attr() or native .getAttribute() method to retreive ‘data-‘ values.

    I use ‘data-‘ myself all the time.

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

Sidebar

Related Questions

I may be missing something in the standard libs, but I don't think so.
I think I may have overlooked something here, but I'm not sure why this
I think I may have used a repeater when I should have used something
I think I may be missing something here or my understanding of rails model
I've bending my mind for a while, but I think I'm missing something, so
Not sure if I'm completely missing something but, I have a typical MVC web
I think I may have encountered a bug in mysql, or is it just
I think I may have a misunderstanding of <xsl:variable\> and <xsl:value-of\> so perhaps someone
I think I may have accidently disabled stylecop in my Visual Studio 2008 enviroment.
I think we may have trouble with our existing project. For some reasons we

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.