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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:43:37+00:00 2026-06-01T04:43:37+00:00

I have the following script $(function(){ $(‘.input1_class, .input2_class, <many other input classes go here>’).bind(‘change’,

  • 0

I have the following script

$(function(){
    $('.input1_class, .input2_class, <many other input classes go here>').bind('change', function(){
        $.ajax({
            url: "<%= update_fields_projects_url %>",
            data: {
                input1: $('.input1_class').val(),
                input2: $('.input2_class').val(),
                <other inputs go here>
            }
        });
    });
});

this is working fine, so if any input is modified, the proper actions are executed and ajax update also runs fine.

Now I wanted to trigger the same ajax request from the click of the following button

<input type=button id=update_button_id value="Update Fields" class=update_button_class>

I was about to duplicate the previous function by changing the header as follows, which I think would work

$(function(){
    $('.update_button_class').bind('click', function(){
        $.ajax({
            url: "<%= update_fields_projects_url %>",
            data: {
                input1: $('.input1_class').val(),
                input2: $('.input2_class').val(),
                <other inputs go here>
            }
        });
    });
});

but I thought that’s not a good solution, because any subsequent changes would have to done in both functions at the same time.

I wonder if there is a better way to write this function only once and to trigger it either from an input “change” or a button “click”

Update1:

I changed to this

function updateFields(){
    $.ajax({
        url: "<%= update_fields_projects_url %>",
        data: {
            input1: $('.input1_class').val(),
            input2: $('.input2_class').val(),
            <other inputs go here>
        }
    });
}

$('.input1_class, .input2_class, <many other input classes go here>').change(updateFields);

<input type=button id=apply_button_id value="Apply Updates" class=apply_button_class onClick="updateFields();">

Update2 :

I also tried

$('.input1_class, .input2_class, ...').bind('change',updateFields);

and that did not work either

Update3 :

The following is what worked for me

function updateFields(){
    $.ajax({
        url: "<%= update_fields_projects_url %>",
        data: {
            input1: $('.input1_class').val(),
            input2: $('.input2_class').val(),
            <other inputs go here>
        }
    });
}

$(function(){
    $('.input1_class, .input2_class, ...').bind('change',updateFields);
});

<input type=button id=apply_button_id value="Apply Updates" class=apply_button_class onClick="updateFields();">
  • 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-01T04:43:38+00:00Added an answer on June 1, 2026 at 4:43 am

    Just give the function a name:

    function func(){
    
    }
    
    $("...").change(func);
    
    <a href="" onclick="func()">Blah</a>
    

    Or even:

    <a id="link">Blah</a>
    

    And then:

    $("...").change(func);
    
    $("#link").click(func);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script: <script type=text/javascript> $(document).ready(function(){ $(#ProjModelChoose).change(function() { $(#ProjModelChooseCOM).attr(name,form + $(this).val()); $(input[name='buyid']).attr(value,
I have the following script: $(document).ready(function() { $('#slideSelect').change(function(){ $('#slideViewer img').attr('src', $(this).val() + '.png'); });
I have the following script: $(function() { $( 'input[id^=event_' ).each(function() { this.datetimepicker({ stepMinute: 15
I have the following script: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1; if((Timer%10==0)||(Timer==1)){
Hi I have the following script in my form function pdf() { var frm
I have the following function. <script type=text/javascript> window.onbeforeprint = expandAll; function expandAll(){ $(.fieldset:gt(0)).slideDown(fast); }
I have the following javascript function: <script type=text/javascript> function quickCardRegister_OnCompleteSave() { publishContent('This is a
I have the following jquery function > <script type=text/javascript> > > $(document).ready(function() { >
I have put together the following mootools script window.addEvent('domready', function() { var shouts =
I have the following: $(document).ready(function() { var myIframe = document.getElementById('myIframe'); var element = myIframe.contentDocument.createElement('script');

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.