...

View Full Version : making text box read only..



raj.33jsr
07-30-2010, 11:59 AM
dear all

i have some read only text box which i want to get in write mode
the code i am trying is..
function f2(txt1,txt2,txt3)
{
document.form1.txt1.readOnly=false;
document.form1.txt2.readOnly=false;
document.form1.txt3.readOnly=false;
}
<input type="text" value="<%=rset.getString(1)%>" readonly id="tex" class="tb2" name="u_name_0"></td>
<td><input type="text" value="<%=rset.getString(2)%>" readonly class="tb2" name="u_pass_0"></td>
<td><input type="text" value="<%=rset.getString(3)%>" readonly class="tb2" name="u_role_0"></td>
<td><input type="submit" value="delete" name="submit_<%= i%>" class="tb3"></td>
<td><input type="button" value="update" onClick="f2('u_name_0','u_pass_0','u_role_0')"></td>

but its not working..
some body help me out..

Philip M
07-30-2010, 12:16 PM
<script type = "text/javascript">
function f2(){
document.form1.u_name_0.readOnly=false;
document.form1.u_pass_0.readOnly=false;
document.form1.u_role_0.readOnly=false;
}
</script>
<form name = "form1">
<input type="text" value="<%=rset.getString(1)%>" readonly id="tex" class="tb2" name="u_name_0"></td>
<td><input type="text" value="<%=rset.getString(2)%>" readonly class="tb2" name="u_pass_0"></td>
<td><input type="text" value="<%=rset.getString(3)%>" readonly class="tb2" name="u_role_0"></td>
<td><input type="submit" value="delete" name="submit_<%= i%>" class="tb3"></td>
<td><input type="button" value="update" onClick="f2()"></td>

</form>


Quizmaster: Which English king succeeded Henry VIII?
Contestant: Henry VII.

raj.33jsr
07-30-2010, 12:26 PM
<script type = "text/javascript">
function f2(){
document.form1.u_name_0.readOnly=false;
document.form1.u_pass_0.readOnly=false;
document.form1.u_role_0.readOnly=false;
}
</script>
<form name = "form1">
<input type="text" value="<%=rset.getString(1)%>" readonly id="tex" class="tb2" name="u_name_0"></td>
<td><input type="text" value="<%=rset.getString(2)%>" readonly class="tb2" name="u_pass_0"></td>
<td><input type="text" value="<%=rset.getString(3)%>" readonly class="tb2" name="u_role_0"></td>
<td><input type="submit" value="delete" name="submit_<%= i%>" class="tb3"></td>
<td><input type="button" value="update" onClick="f2()"></td>

</form>


Quizmaster: Which English king succeeded Henry VIII?
Contestant: Henry VII.
thanks dear but..
In my application dynamically text box are creating so i must hve to pass the text box name .
i cant call the name statically..

Kor
07-30-2010, 12:43 PM
To make a form element readonly


element.setAttribute('readOnly','readonly');

To make a form element editable again:


element.removeAttribute('readOnly');


And the safe standard HTML/XHTML syntax for the readonly attribute is:


<element readonly="readonly">

Because in strict DTD, all the HTML attributes must have a value, but that value may not be a Boolean (because HTML values of all the attributes are strings). In other elder DTD (transitional HTML), it does not matter.

Old Pedant
07-30-2010, 10:48 PM
Everything Kor said is true, but doesn't at all answer your question.

If you are *NOT* using STRICT DTD, then this will do the job:



function f2(name1, name2, name3 )
{
document.form1.elements[name1].readOnly=false;
document.form1.elements[name2].readOnly=false;
document.form1.elements[name3].readOnly=false;
}
...
<td><input type="button" value="update" onClick="f2('u_name_0','u_pass_0','u_role_0')"></td>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum