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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:45:44+00:00 2026-05-21T06:45:44+00:00

I would like to move all Javascript from HTML markup into separate files but

  • 0

I would like to move all Javascript from HTML markup into separate files but I’m still fighting with the following:

Let’s say I have a table with many rows (users table) and for every user I need a button to call a function. Now I do this for every row:

<button onClick='doSomething(a,b,c);'>Edit</button>

I know I can use a class attribute to tell for example jQuery that all the buttons with some class should call a javascript function doSometing. However I don’t know how to pass parameters (a,b,c) to that function. These parameters, as I expect, must be on every row in the table, but where to put them?

Just a note: a,b,c are different for every row. Example:

<tr>
  <td>1</td>
  <td>John</td>
  <td><button onclick="doSomething(1,3,5);">Work!</button></td>
</tr>
<tr>
  <td>2</td>
  <td>Merry</td>
  <td><button onclick="doSomething(2,7,9);">Work!</button></td>
</tr>

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-21T06:45:44+00:00Added an answer on May 21, 2026 at 6:45 am

    One way would be simply place the values in a hidden field.

    <input type="hidden" class="values" value="1,2,3"/>
    <input type="button" class="hiddenInput" value="Do it"/>
    

    Where each , is a value for the function. In your jQuery click you can use
    .siblings(.values)

    $(".hiddenInput").click(function() {
        var values = $(this).siblings(".values").val().split(',');
        var a = values[0];
        var b = values[1];
        var c = values[2];
        DoSomething(a, b, c);
    });
    

    Now if you are using jQuery 1.4.3 or greater jQuery will automatically parse data-* attributes. Things become a bunch easier.

    <input type="button" class="dataAttr" data-values='{"a": "1", "b": "2", "c": "3"}' value="Do it"/>
    

    This allows you to store a value or even a complex json object in this data-* attribute and jQuery will parse it automatically.

    $(".dataAttr").click(function() {
        var values = $(this).data("values");
        DoSomething(values.a, values.b, values.c);
    });
    

    Code example on jsfiddle

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

Sidebar

Related Questions

I would like to move a file or folder from one place to another
Our team would like to move from the Visual SourceSafe (VSS) to the Team
I have two XmlDocuments and I would like to move an XmlNode selected from
I would like to know if it is possible to copy/move files to a
I have large number of files with .gif extension. I would like to move
I Have a treeView Already populated (in vb.net) and would Like to move all
I have a Pylons app where I would like to move some of the
I am using Jython to move images around and organise them. I would like
I would like to get a sum from a column, with and without a
I would like to know how to merge these two Javascript ajax scripts. So

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.