Solved

how can I set all inputs to readonly in jquery?

Posted on 2010-08-25
9
675 Views
Last Modified: 2012-05-10
Hello guys

When I open my page I'd like to set all inputs to readonly, how can I do this?

thanks
0
Comment
Question by:hidrau
9 Comments
 
LVL 3

Expert Comment

by:johnsy32
Comment Utility
$(":input").attr('readonly','readonly');
0
 
LVL 14

Assisted Solution

by:sam2912
sam2912 earned 100 total points
Comment Utility
don't need semi-colon
$("input").attr('readonly','readonly');
0
 
LVL 3

Assisted Solution

by:wuff
wuff earned 100 total points
Comment Utility
use this on all input fields you want to have readonly:

.attr('readonly', true)

Example: $('#inputId').attr('readonly', true);
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
can I set them by class?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:hidrau
Comment Utility
and to add this attribute how can I add ?

$(). ????
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
to remove I do this:

$('#target').removeAttr("disabled");

and to add ?
0
 
LVL 3

Accepted Solution

by:
johnsy32 earned 300 total points
Comment Utility
By class...

$(".className").attr('readonly','readonly');
0
 
LVL 3

Expert Comment

by:johnsy32
Comment Utility
to add disabled...

$('#target').attr('disabled','disabled');
0
 
LVL 1

Author Closing Comment

by:hidrau
Comment Utility
thanks everybody
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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)

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now