By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,481 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,481 IT Pros & Developers. It's quick & easy.

How to make a non editable textfields editable at a button click?

P: 2
I have some text fields which are non editable .I want to make them editable at a button(Edit) click.Below is the code .How to do that??

Expand|Select|Wrap|Line Numbers
  1.  <FORM action="notworking.jsp" name="abc">  
  2.  
  3.             <label>First Name:
  4.  
  5.             </label>
  6.                       <positiontextbox>
  7.             <input type="text" name="fname" value="<%=rs.getString(1)%>"  id="fn" readonly />
  8.                  </positiontextbox>
  9.             <div class="spacer"></div>
  10.             <br>
  11.             <label>Last Name:
  12.  
  13.             </label>
  14.             <input type="text" name="lname"  value="<%=rs.getString(2)%>" id="ln"  readonly/>
  15.  
  16.             <div class="spacer"></div>
  17.             <br>
  18.             <label>Your Email:
  19.  
  20.             </label>
  21.             <input type="text" name="email" value="<%=rs.getString(3)%>"id="email" readonly/>
  22.  
  23.   <div class="spacer"></div>
  24.             <br>
  25.         <div class="spacer"></div><br>
  26.  
  27.     <INPUT type=submit value="Edit"   onclick="return validate()"><a></a>
  28.     <hr>
  29.     </hr>    
  30.              </FORM>
Apr 7 '12 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 1,043
look here

which basically is:
1) you need javascript
2) don't use 'readonly', but use 'disabled="true"'
Apr 7 '12 #2

P: 2
Thanks.Can you please tell me how to make these fields(3) enable at button click?
Apr 8 '12 #3

Expert 100+
P: 1,043
Please use the CODE-tags around some code you post here:
Expand|Select|Wrap|Line Numbers
  1. <FORM action="notworking.jsp" name="abc"> 
  2.  
  3.  
  4. <script type="text/javascript">
  5. function validate() {
  6.     x=document.getElementById("fn")
  7.     x.disabled = !x.disabled;
  8.     x=document.getElementById("ln")
  9.     x.disabled = !x.disabled;
  10.     x=document.getElementById("email")
  11.     x.disabled = !x.disabled;
  12. }
  13. </script>
  14.  
  15. <label>First Name:
  16.  
  17. </label>
  18. <positiontextbox>
  19. <input type="text" name="fname" value="<%=rs.getString(1)%>" id="fn" disabled="true" />
  20. </positiontextbox>
  21. <div class="spacer"></div>
  22. <br>
  23. <label>Last Name:
  24.  
  25. </label>
  26. <input type="text" name="lname" value="<%=rs.getString(2)%>" id="ln" disabled="true"/>
  27.  
  28. <div class="spacer"></div>
  29. <br>
  30. <label>Your Email:
  31.  
  32. </label>
  33. <input type="text" name="email" value="<%=rs.getString(3)%>"id="email" disabled="true"/>
  34.  
  35. <div class="spacer"></div>
  36. <br>
  37. <div class="spacer"></div><br>
  38.  
  39. <INPUT type=button value="Edit" onclick="return validate()"><a></a>
  40. <hr>
  41. </hr> 
  42. </FORM>
note:
1. the button type on the edit button changed
2. "readonly" was changed to "disabled='true'"
Apr 8 '12 #4

P: 93
<input type="text" readonly="readonly">
Apr 16 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.