/    Sign up×
Community /Pin to ProfileBookmark

making a field readonly

I created a javascript fnnction and am trying to make a forms field (add) read only with the text N/A in it? heres what I think…Thanks

document.loanapp.add.readonly.text = N/A;

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterFeb 04.2005 — I'm gonna "Cheat" this time.

<i>
</i>&lt;script&gt;
function ONLD(){
text_field.outerHTML='&lt;input type="text" value="HI" ID="text_field" readonly&gt;'
}
&lt;/script&gt;
&lt;body onload=ONLD()&gt;
&lt;input type="text" value="HI" ID="text_field"&gt;
&lt;/body&gt;
Copy linkTweet thisAlerts:
@UltimaterFeb 04.2005 — Ok, fine ,I won't cheat :smiles:
<i>
</i>&lt;script&gt;
function ONLD(){
text_field.readOnly=true
}
&lt;/script&gt;
&lt;body onload=ONLD()&gt;
&lt;input type="text" value="HI" ID="text_field"&gt;
&lt;/body&gt;


The onload part is needed, otherwise the code is executed before the object exsists.
Copy linkTweet thisAlerts:
@lukeurtnowskiauthorFeb 04.2005 — is there a way to do this or run the function only when a certain value (1) is selected.
Copy linkTweet thisAlerts:
@UltimaterFeb 04.2005 — Oh, sorry I forgot to say, "Hello!"

Hello!

lol ?

Yes, It's possible to call the function in many ways.

As long as the function is not called [b]before[/b] the

object exists.

Here's the code you requested:

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
function ONLD(){
text_field.readOnly=false;
TCB.checked=false
}
function Toggle_text_field(){
if(arguments[0]==true){
text_field.readOnly=true;return true;
}
if(arguments[0]==false){
text_field.readOnly=false;return true;
}

}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="ONLD()"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;input type="text" value="HI" ID="text_field"&gt;
&lt;/td&gt;&lt;td&gt;
Read Only&lt;input type="checkbox"
onclick="Toggle_text_field(this.checked)" ID="TCB"&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@UltimaterFeb 04.2005 — btw don't let the [b]onclick[/b] event fool you.

With checkboxs, onclick also includes any method you use to

check or uncheck it.

For example:

Using the [b]tab[/b] button to select the checkbox and using [b]space bar[/b] to toggle it.

Doing so will toggle the checkbox and invoke the event [b]onclick[/b].
Copy linkTweet thisAlerts:
@PittimannFeb 04.2005 — Hi!

This would work in browsers other than IE:[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
</head>
<body>
<form>
<input value="blah" name="txt">
<input type="checkbox" onclick="this.form.txt.readOnly=this.checked;">
</form>
</body>
</html>[/code]
The incorrect referencing would prevent most browsers other than IE to not execute the code at all and Firefox would at least throw out a warning. And please, Ultimater, do not consider my post as an attempt to insult you or whatever else like you recently did in another case.

Cheers - Pit

Edit: meta tag moved elsewhere
Copy linkTweet thisAlerts:
@lukeurtnowskiauthorFeb 04.2005 — You're all over the place, thanks pittman!

I'm eventuallly going to put this thing in that if statement also.

So will it be different?
×

Success!

Help @lukeurtnowski 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 5.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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