/    Sign up×
Community /Pin to ProfileBookmark

Toggle READONLY ?

Is there a way to alter the state of a textbox so that at times
it is READONLY true (disabled=true or edits not allowed) and at other times be false (disabled=false or edits allowed)

I can’t get this to work.

[code=php]
<input id=”Tbox” type=”text” value=””>

<input type=”button” onClick=”document.getElementById(‘Tbox’).disabled=true” value=”Set READONLY”>
<input type=”button” onClick=”document.getElementById(‘Tbox’).disabled=false” value=”Reset READONLY”>
[/code]

Obviously I’m doing something wrong, but I don’t see it yet!

Thanks in advance.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@PalrosApr 27.2007 — I don't see what's wrong. I just tested it in IE7 and it works fine.
Copy linkTweet thisAlerts:
@s_b37Apr 27.2007 — try disabled='disabled' or disabled=''

im not sure but some browsers mite prefer that

btw: wat browser ru using
Copy linkTweet thisAlerts:
@samanyoluApr 27.2007 — read[color=red]O[/color]nly
<br/>
&lt;input id="Tbox" type="text" value="JMRKER"&gt;

&lt;input type="button" onClick="document.getElementById('Tbox').readOnly=true" value="Set READONLY"&gt;
&lt;input type="button" onClick="document.getElementById('Tbox').readOnly=false" value="Reset READONLY"&gt;
Copy linkTweet thisAlerts:
@JMRKERauthorApr 27.2007 — Thanks for all the responses.

I have not a clue as to what I was doing wrong.

I re-entered and re-freshed the script in both FF and IE

this morning and all versions work fine ?

But on a happy note ?, all versions posted work fine.

For posterity, here is the final working script.
[code=php]
<html>
<head>
<title>ReadOnly Toggle Test</title>
</head>
<body>
<input id="Tbox" type="text" value="">
<p />
<input type="button"
onClick="document.getElementById('Tbox').disabled=true" value="Set disabled TRUE">
<input type="button"
onClick="document.getElementById('Tbox').disabled=false" value="Reset disabled FALSE">

<input type="button"
onClick="document.getElementById('Tbox').readOnly=true" value="Set readOnly TRUE">
<input type="button"
onClick="document.getElementById('Tbox').readOnly=false" value="Reset readOnly FALSE">

</body>
</html>
[/code]


Again, thanks to all who responsed.
Copy linkTweet thisAlerts:
@JMRKERauthorApr 27.2007 — To Moderators:

What buttons, checkboxes or radio buttons do I press to indicate that a posted problem has been resolved?

Thanks.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...