Link to home
Start Free TrialLog in
Avatar of hariaspind
hariaspind

asked on

how to read textbox attribute through jquery and findout is it readonly

How to get the value of texbox attribute readonly and set other textbox to readyonly
Avatar of szewkam
szewkam
Flag of Poland image

The attr function: http://api.jquery.com/attr/
Avatar of hariaspind
hariaspind

ASKER

I tried this  .this code sets the  readonly att to "true" .but the textbox is still editable.But why ?

$("#divResult").find("textarea").attr('ReadOnly', true);
true isn't a boolean, but text ;). Try:
$("#divResult").find("textarea").attr('ReadOnly', 'true'); - works for me
Avatar of leakim971
check this :


<!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" />
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("#but").click(function() {
			// get the value of the readonly textbox
			var val = $("input[readonly='readonly']").val();
			// set the value of the writeable textbox
			$("input[readonly!='readonly'][type='text']").val(val);
			// set it as readonly
			$("input[readonly!='readonly'][type='text']").attr("readonly","readonly");
		});
	});
</script>
</head>
<body>
<input type="text" readonly="readonly" value="I'm readonly" />
<br />
<br />
<input type="text" value="you can modify my value" />
<br />
<br />
<input type="button" id="but" value="search readony and set readonly" />
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank.I got my issue fixed.