Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jQuery: Best way to disabled input

Posted on 2012-04-02
4
Medium Priority
?
325 Views
Last Modified: 2012-04-03
Which is best?
$('#xyz').attr("disabled", true); 
$('#xyz').attr("disabled", "true"); 
$('#xyz').attr("disabled", "disabled"); 

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
ID: 37799144
$('#xyz').attr("disabled", "disabled"); ¿
or :
$('#xyz').attr("disabled", ""); ¿

http://www.w3.org/TR/html-markup/input.submit.html

in the jQuery plugin you can find this line :
elem.setAttribute( name, "" + value );

Open in new window


where elem is your input
name is the disabled attribute
the second argument is a string
0
 
LVL 7

Assisted Solution

by:robertark
robertark earned 500 total points
ID: 37799206
Use .prop() - http://api.jquery.com/prop/

$('#elem').prop('disabled', true)
$('#elem').prop('disabled', false)

Open in new window

0
 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 500 total points
ID: 37799374
If you are using latest version of jquery then use prop otherwise $('#xyz').attr("disabled", "disabled");
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
ID: 37799643
I prefer:

$('#xyz').attr( { disabled: true } );

because you can add more stuff:

$('#xyz').attr( { disabled: true, value: "Locked" } );

works with prop too:

$('#xyz').prop( { disabled: true } );
$('#xyz').prop( { disabled: true, value: "Locked" } );
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

671 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question