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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:41:29+00:00 2026-05-31T07:41:29+00:00

I have a input field. When the onchange event is triggered, I want to

  • 0

I have a input field. When the onchange event is triggered, I want to enable a jQuery button based on a LI element. I want to have the same behaviour as a normal button would do. The problem is, if I click on button when it’s disabled, jQuery catches the event and prevents the default behaviour to occurs, which should release the focus on the input field and trigger the onchange event before the onclick is triggered on the button.

I’m using jQuery 1.6.4 with jQuery UI 1.8.16 in Chrome.

In this live demo : http://jsfiddle.net/francisfortier/QMDc2/5/, you have three fieldsets. The first one uses a standard button, the second one, a jQuery button based on a li and the third one, use again a jQuery button based on a li with a special hack to manually release the focus from the input field on the click capture. This third fieldset can solve my problem on modern browsers, but it will not in IE8 because it requires to use event capturing.

Do you have a better cross browser solution to have the same behaviour with a jQuery button as a standard button?

Thank you

  • 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-31T07:41:30+00:00Added an answer on May 31, 2026 at 7:41 am

    What about adding .unbind('click') before your click handler:

    $('#jQueryButton').find('li').button({
        disabled: true
    }).unbind('click').click(function() {
        alert('Hello ' + $(this).closest('fieldset').children('input:first').val() + ' !');
    });
    

    Demo: http://jsfiddle.net/jtbowden/yPHKp/

    Of course, then you have to add the smarts to the click handler to not execute when the input is empty:

    $('#jQueryButton').find('li').button({
        disabled: true
    }).unbind('click').click(function() {
        if($('#jQueryButton').children('input').val()) {
            alert('Hello ' + $(this).closest('fieldset').children('input:first').val() + ' !');
        }
    });
    

    Demo: http://jsfiddle.net/jtbowden/yPHKp/1/

    Or, you could add a keyup handler. Then the change is made before the button is clicked:

    $('#jQueryButton').children('input').bind('change keyup', function() {
        var self = $(this);
    
        self.closest('fieldset').find('.ui-button').button(self.val() ? 'enable' : 'disable');
    });
    

    Demo: http://jsfiddle.net/jtbowden/GcnYz/1/

    A better solution might be to unbind the click.button handler and then rebind it with the addition of a .blur() event to the input fields:

    $('#jQueryButton').find('li').button({
        disabled: true
    }).unbind('click.button').bind('click.button', function(event) {
        $('#jQueryButton').children('input').blur();
        if ($(this).button("option", "disabled")) {
            event.preventDefault();
            event.stopImmediatePropagation();
        }
    }).click(function() {
        alert('Hello ' + $(this).closest('fieldset').children('input:first').val() + ' !');
    });
    

    This retains all of your validation in place, plus forces the change event to happen before the button click. You could integrate the final .click() handler into the click.button event by putting the guts in an else block.

    Demo: http://jsfiddle.net/jtbowden/GcnYz/2/

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

Sidebar

Related Questions

I'm handling the onChange event of an HTML input file field by using jQuery's
I have an input field with onChange event which triggers an AJAX call which
I have an input field which has a placeholder text. I want one word
I have an input field and I want to limit it to alphanumerical (A-Z,
I have an input field in a form. Upon pushing submit, I want to
i have an input field which will be displayed. i want that to hide
I have an input field with an id that is used as a button.
I have an input element with onchange=do_something(). When I am typing and hit the
Update input field event onchange ? $A = array(A,B,C,D); <select name="A" id="A" onchange="change_val()"> <?php
I have a JavaScript input object with type="text" coming along with an onchange event

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.