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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:36:26+00:00 2026-06-06T18:36:26+00:00

I have a jsfiddle here . jQuery $(function() { //var input = $(‘form :input[type=text]’)

  • 0

I have a jsfiddle here.

jQuery

$(function() {
    //var input = $('form :input[type="text"]')
    $('form :input[type="text"]').live('keyup', function() {
        $('form .create-playlist-button')
            .attr('disabled', $('form :input[type="text"]').val().length == 0);
    });
});

Needed

  • When I start entering the data in the textbox, create should be enabled.

  • When I remove all text from the textbox, create should be disabled.

I am very new to jQuery and this thing is not working for me.

  • 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-06T18:36:26+00:00Added an answer on June 6, 2026 at 6:36 pm
    $('form :input[type="text"]').live('keyup', function() {
          var val = $.trim(this.value); // this.value is faster than $(this).val()
          $('form .create-playlist-button').prop('disabled', val.length == 0);
    });
    

    DEMO

    Here, I used .prop() instead of .attr(), according to jQuery doc .prop() should be use. I also used .trim() for removing the whitespace from the beginning and end of value.


    About your code

    In your code you used $('form :input[type="text"]') two times, one for bind event and one to getting the value of text field. But that is not necessary, because within keyup event handler function this will refers to that input element on which keyup event binded.

    If you sometime need to use any selector multiple times for any purpose it will be better to cache that in a variable and reuse that variable. Just for example:

    var input = $('form :input[type="text"]');
    input.on('click', function() {
          alert( this.value );
          input.addClass('something');
    });
    

    If would be better if you use .on() instead of .live() for delegate event handler, because .live() has been deprecated.

    You can use .on() like following:

    $('form').on('keyup', ':input[type="text"]', function() {
       var val = $.trim(this.value);
       $('form .create-playlist-button').prop('disabled', val.length == 0);
    });
    

    Note

    Syntax of .on() for delegate event handling is like:

    $(staticContainer).on( eventName, target, handlerFunction )
    

    Here, staticContainer point to an element which belong to DOM at page load, i.e which is not dynamic and also container of target on which you want to bind your event.


    Just for some more go here

    • .prop() vs .attr()

    • http://forum.jquery.com/topic/whats-the-difference-between-jquery-attr-and-jquery-prop

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

Sidebar

Related Questions

I have a jsfiddle here - http://jsfiddle.net/9kKXX/20/ My jQuery function $(function() { $('form input[type=text]').live('keyup',
I have my form elements here: <li><div id=formanswer1 class=clonedInput>Answer: <input type=text id=formanswer1 value= /></div></li>
I have a simple jQuery function: $('#selectable1 span').live('mousedown', function() { var ff = $(this).css(font-family);
I have a fiddle here http://jsfiddle.net/WULsZ/1/ I load jQuery first and the code is
I have a Jsfiddle application here . If you type in a question in
My script is here : jsfiddle i have two attributes in my form that
Hello I have a jquery function called create time box This creates a textbox
I have some jquery that smoothly resizes a text input on click. It all
I have this javascript, jquery function, (below) It gets the text inside each table
new to jquery here, right now I have a working hide/show function when one

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.