Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how can I set all inputs to readonly in jquery?

Posted on 2010-08-25
9
Medium Priority
?
717 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
ID: 33520933
$(":input").attr('readonly','readonly');
0
 
LVL 14

Assisted Solution

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

Assisted Solution

by:wuff
wuff earned 400 total points
ID: 33520968
use this on all input fields you want to have readonly:

.attr('readonly', true)

Example: $('#inputId').attr('readonly', true);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:hidrau
ID: 33521000
can I set them by class?
0
 
LVL 1

Author Comment

by:hidrau
ID: 33521011
and to add this attribute how can I add ?

$(). ????
0
 
LVL 1

Author Comment

by:hidrau
ID: 33521021
to remove I do this:

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

and to add ?
0
 
LVL 3

Accepted Solution

by:
johnsy32 earned 1200 total points
ID: 33521122
By class...

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

Expert Comment

by:johnsy32
ID: 33521148
to add disabled...

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

Author Closing Comment

by:hidrau
ID: 33521253
thanks everybody
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…
Suggested Courses

971 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