[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

How can I set readOnly to all my inputs with Jquery?

I have many inputs from my page, I only to set all of them to readOnly.

How can I do this?

thanks
0
hidrau
Asked:
hidrau
  • 6
  • 3
  • 3
2 Solutions
 
leakim971PluritechnicianCommented:
Use for textbox : $("input[type='text']).attr("readonly","readonly");
0
 
leakim971PluritechnicianCommented:
I miss a double quote : $("input[type='text']").attr("readonly","readonly");
0
 
Gurvinder Pal SinghCommented:
$(":input").each(function(){
  $(this).attr("readonly", true);
});

see this link on how to get all the inputs
http://api.jquery.com/input-selector/

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
leakim971PluritechnicianCommented:
readonly attribute don't work on checkbox and radio, you may want to disable radio and checkbox : $("input[type='checkbox'],input[type='radio']").attr("disabled","true");

test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("input[type='text']").attr("readonly","readonly");
		$("input[type='checkbox'],input[type='radio']").attr("disabled","true");
	});
</script>
</head>
<body>
<input type="text" /><br>
<input type="text" /><br>
<input type="text" /><br>
<input type="text" /><br>
<input type="text" /><br>
<input type="text" /><br>
<input type="text" /><br>
<input type="text" /><br>
<input type="text" /><br>
<input type="text" /><br>
<input type="submit" /><br>
<input type="radio" /><br>
<input type="checkbox" /><br>
</body>
</html>

Open in new window

0
 
Gurvinder Pal SinghCommented:
ok, in that case, shouldn't we disable all the inputs?

$(":input").attr('disabled', 'disabled');
0
 
hidrauAuthor Commented:
ok,

and how can I do this in select?
0
 
leakim971PluritechnicianCommented:
if you disable them all, you can't get their value on server side (form POST/GET)
0
 
Gurvinder Pal SinghCommented:
<<and how can I do this in select?>>
it takes care of select as well.

<<if you disable them all, you can't get their value on server side (form POST/GET)>>
I think he can enable it back using a similar
$(":input").removeAttr('disabled');

Similar logic will be applied to checkboxes as well, since they cannot be set to readonly.



0
 
hidrauAuthor Commented:
ok, I will open another thread with this question for select
0
 
hidrauAuthor Commented:
thanks
0
 
leakim971PluritechnicianCommented:
>I think he can enable it back using a similar

by clicking on a disabled select or input/submit button ? ;o)
0
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
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.

  • 6
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now