• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

making the textbox readonly

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
I have a form 'form1' in which there is a textbox 'text1' and a bunch of radio buttons. When the user clicks a radio button, I invoke a javascript function. Based on the value of the radio button clicked, I need to make the text in the textbox 'text1' readonly and not editable.
How can I do this in the javascript function?
Any help could be appreciated.
Chuck
 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
<HTML>
<HEAD>
<script language="Javascript">
function Enable() {
document.form1.text1.disabled = false;
}
function Disable() {
document.form1.text1.disabled = true;
}
</script>
</HEAD>
<BODY>
<form name=form1>
<input type="text" name=text1 id=text1 size=10>
<input type="radio" name="R1" id="R1" value="Enable" onClick="Enable()"> Enable
<input type="radio" name="R1" id="R1" value="Disable" onClick="Disable()"> Disable
</form>

</BODY>
</HTML>
 
Chuck Meduri
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi DilipKumar,
The solution you provided works great if you want to disable it. But I don't want to disable it. The problem with disabling the field is the information is not sent to the server. I want to make it readonly so that the text in the text box is sent to the server
.
Chuck
 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This could work:
function Enable() {
document.form1.text1.readOnly = false;
}
function Disable() {
document.form1.text1.readOnly = true;
}
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chuck,
I think your best bet is to ensure that when the textbox
gets the focus it loses the focus.
eg (not exact synthax but you get the idea)
if (myText.focus == true)myText.focus = false;
so the text won't be changed & it won't be disabled.
HTH ,
Dave
 
Chuck Meduri
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dilip,
I have already tried this but this does not work.
Chuck

Originally posted by Dilipkumar Kalyankar:
This could work:
function Enable() {
document.form1.text1.readOnly = false;
}
function Disable() {
document.form1.text1.readOnly = true;
}


 
Dilip kumar
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strange ! It works on my machine. I have IE5.
 
Chuck Meduri
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is working now. All the while I was trying
document.formName.textFieldName.readonly = true;
while it is actually
document.formName.textFieldName.readOnly = true;(javascript is case-sensitive)
Thank you very much,
Chuck

Originally posted by Dilipkumar Kalyankar:
Strange ! It works on my machine. I have IE5.


 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You can disable the text box liek this also.
call blur on focus of the object!!!.
It works in all types of browsers
function aa()
{
//alert("onload");
document.main.dummy.blur();
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" ()">
<Form name="main" method="post" action="test2.jsp">
<INPUT type=" text" NAME="dummy" value="hi dummy" onFocus="aa()">
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
function blur(element) {
element.blur;
}
...
<input type="Text" name="input1" value="" size="20" onfocus="javascript:blur(this);">
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You pulled up a post from 2001....look at the date!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic