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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:56:35+00:00 2026-06-08T04:56:35+00:00

How can I pass arguments to a function that is assigned to variable. For

  • 0

How can I pass arguments to a function that is assigned to variable.
For example:

var updateDiv = function() {
   var row = this;
   var values = "";
   $('input[type=text],textarea,input[type=radio]:checked,input[type=checkbox]:checked', this).each(function() {
       if ($(this).val()!="" && $(this).val()!=null) {
           if (values!="") values = values + ","+ $(this).val();
           else values +=  $(this).val();
         }
       });
      if (values!="") { 
       if(values.substring(0,1)==",") values = values.substring(1) +"<br>";
       else values = values +"<br>";
      } 
      $('.jist', row).append(values);
}

$('tr:has(input)').each(updateDiv);
$('tr:has(textarea)').each(updateDiv);

HTML:

<tr>
<td>ai</td><td> <input type="text" name="ai" id="ai"></td>
<td><input type="checkbox" name="ana" id="ana" value="N/A"></td>
<td><div class="jist"></div></td>
</tr>

I want to pass arguments to updateDiv -> updateDiv("mystring");
and I want to use “mystring” in the function this way – > $('.'+mystring, row).append(values);

  • 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-08T04:56:36+00:00Added an answer on June 8, 2026 at 4:56 am

    Simple and Clean

    Not sure how I missed the obvious here.

    jQuery

    var updateDiv = function(divClass) {    
        ...
        $(divClass, row).append(values);
    }
    
    $('tr:has(input)').each(function(){ updateDiv('.hist'); });
    $('tr:has(textarea)').each(function(){ updateDiv('.something-else'); });
    

    .

    Global Variable Method

    You could assign global variables with the class name. By defining the variable before each .each() the updateDiv function uses a different class name.

    jQuery

    var updateDiv = function() {    
        ...
        $(window.divClass, row).append(values);
    }
    
    window.divClass = '.hist';
    $('tr:has(input)').each(updateDiv);
    window.divClass = '.something-else';
    $('tr:has(textarea)').each(updateDiv);​
    

    .

    HTML5 Data Method

    You could assign values as data objects to the elements which are being called. I also cleaned up some of your selectors and jQuery redundancies.

    Fiddle: http://jsfiddle.net/iambriansreed/KWCdn/

    HTML

    <table>
        <tr data-update=".hist">
            <td>AutoI</td>
            <td> <input type="text" name="autoIH_complaint" id="autoIH_complaint"></td>
            <td><input class="NA" type="checkbox" name="autoINA" id="autoINA" value="N/A"></td>
            <td><div class="hist"></div></td>
        </tr>
    </table>
    

    jQuery

    var updateDiv = function() {
    
        var row = this, values = "";
        $('input:text,textarea,:radio:checked,:checkbox:checked', this).each(function() {
            if (this.value != "" && this.value != null) {
                if (values != "") values = values + "," + this.value;
                else values += this.value;
            }
        });
        if (values != "") {
            if (values.substring(0, 1) == ",") values = values.substring(1) + "<br>";
            else values = values + "<br>";
        }
        $(row.data('update'), row).append(values);
    }
    
    $('tr:has(input)').each(updateDiv);
    $('tr:has(textarea)').each(updateDiv);​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way that I can pass arguments in selector? example: I have
I know you can pass arguments through the RunWorkerAsync function call when you first
How can I pass arguments to my lua dll function? I made a simple
How can I pass back some arguments from a window that is closed? For
I noticed today that I can't use * to pass width or precision arguments
I have a function that takes a variable number of arguments in C that
I am trying to pass some data to a function that uses those arguments
How can I bind arguments to a Python function so that I can call
I've adapted the Crockford object() function so that I can pass in some parameters
I defined a function that can take any number of arguments but none is

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.