Solved

how can I set all inputs to readonly in jquery?

Posted on 2010-08-25
9
682 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
[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
9 Comments
 
LVL 3

Expert Comment

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

Assisted Solution

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

Assisted Solution

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

.attr('readonly', true)

Example: $('#inputId').attr('readonly', true);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 300 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
$q.all is slower or not  in  Angularjs 2 35
how to use .length with "input" 2 32
jQuery parseHTML 6 44
modify change color of text 9 33
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…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
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…

740 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