Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Read Only Properties 1

Status
Not open for further replies.

webmast

Programmer
Dec 21, 2001
57
IN
I am facing a difficulty with setting readonly property for a text box through radio buttons.

Example
----------
Imagine there is a text box which shows the value from the database (say : height). Now this text box will be in the readonly mode intially. Below that text box we have an option Edit Now Yes or No (two radio buttons)When the user clicks on the Yes the textbox must be editable, but incase he edits it and then click back on No, the earlier default value (ie) the value from the database must get back into it and the textbox must become readonly. So when I submit the page, the value doesnt get affected.

I am coding using JSP, but if some one can help me on the Javascript it will be very helpful.

Thanx a lot in advance...

Tommy...
 
Try this:

Code:
<FORM NAME="f">

<INPUT TYPE="TEXT" NAME="text" VALUE="height" DISABLED><BR><BR>

Edit:
<INPUT TYPE="RADIO" NAME="editOption" onClick="document.f.text.disabled=false;">Yes
<INPUT TYPE="RADIO" NAME="editOption" CHECKED onClick="document.f.text.value=document.f.text.defaultValue; document.f.text.disabled=true;">No


</FORM>


Ben.
 
Thank you Ben but this only solves one part of my problem, ie the default value retension. But incase i submit when the text box is disabled the value passed to the next page is 'null' I want the value to be sent. Plz help.

Tommy
 
What you need to do is 'undisable' the text box onSubmit or equivalent, then the value will be passed back.

for example you could do this -

<body onSubmit="document.f.text.disabled=false;">

I've not tried this but if it doesn't work try putting 'document.f.text.disabled=false' into a function and calling the function when you submit the form.

hth

Stewart
 
Fair point, you said readonly (not disabled) first

Just use readOnly in the example instead of disabled, eg:

Code:
onClick="document.f.text.readOnly=false;"


Not used it before, but works in Safari, so should be OK!

Ben.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top