/    Sign up×
Community /Pin to ProfileBookmark

Clear a text box when disabling it?

Is there any way to clear a text box when you disable it? I have the following code:

[CODE]
function DisableName(aStatus) {
if (aStatus == 1) {
document.form1.R1.disabled = true ;
document.form1.R9.disabled = true ;
document.form1.R10.disabled = true ;
document.form1.R11.disabled = true ;
document.form1.R12[0].disabled = false ;
document.form1.R12[1].disabled = false ;
document.form1.R12[2].disabled = false ;
document.form1.R13.disabled = true ;
document.form1.R14.disabled = true ;
document.form1.R15.disabled = true ;
istatus = “1”
}
else {
document.form1.R1.disabled = false ;
document.form1.R9.disabled = true ;
document.form1.R10.disabled = false ;
document.form1.R11.disabled = false ;
document.form1.R12[0].disabled = true ;
document.form1.R12[1].disabled = true ;
document.form1.R12[2].disabled = true ;
document.form1.R13.disabled = true ;
document.form1.R14.disabled = false ;
document.form1.R15.disabled = false ;
istatus = “1”
}
[/CODE]

R1 is a text box. When this function runs, it disables the text box. However, I would like to clear the contents out of it at the same time. Can that be done?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisSep 16.2009 — document.form1.R1.value = "";etc.
Copy linkTweet thisAlerts:
@lordvaderiiiauthorSep 16.2009 — document.form1.R1.value = "";etc.[/QUOTE]
That was the first thing I tried and it doesn't clear the text box. It still just disables it with the entered text in it.
Copy linkTweet thisAlerts:
@toicontienSep 16.2009 — Maybe this will help?
[CODE]function disableAndClearField( field ) {
if ( field.nodeName == "INPUT" ) {
if ( field.type == "text" ) {
field.value = "";
}
else if ( field.type == "checkbox" || field.type == "radio" ) {
field.checked = false;
}
}
else {
field.value = "";
}

field.disabled = true;
field = null;
}[/CODE]

And to use it:
[CODE]var myField = document.getElementById( "field_id" );

disableAndClearField( myField );[/CODE]
Copy linkTweet thisAlerts:
@lordvaderiiiauthorSep 16.2009 — Thanks. The first one ended up working (as soon as I put it in the right function). ?
×

Success!

Help @lordvaderiii 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.24,
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,
)...