/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] disabling form inputs

hi experts,

i have a form where a user can either enter a filename into a [B]input type=”text”[/B] (if the user already uploaded the file via ftp), or he can select a file via [B]input type=”file”[/B] to upload the file via the form.

to avoid conflict i want to disable either the textfield or the file field once there´s something entered into the other, all in realtime and before the submit button is pressed.

any ideas on how to approach this?

thanks in advance,
jogol

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 02.2008 — <form action="#" name="form1">
<input type="text" name="textFilename" onchange="document.form1['fileFilename'].disabled=true;">
<input type="file" name="fileFilename" onchange="document.form1['textFilename'].disabled=true;" enctype="multipart/form-data">
</form>
Copy linkTweet thisAlerts:
@jogolauthorSep 02.2008 — thanks Fang,

is there a workaround in case the user enters a value into the text field but deletes it again? the way it is now the file field doesnt become active again then.
Copy linkTweet thisAlerts:
@FangSep 02.2008 — Fx won't let you change the file input back to it's original state. IE does allow this.<form action="#" name="form1">
<input type="text" name="textFilename" onchange="if(this.value!=defaultValue){document.form1['fileFilename'].disabled=true;}else{document.form1['fileFilename'].disabled=false;}">
<input type="file" name="fileFilename" onchange="if(this.value!=defaultValue){document.form1['textFilename'].disabled=true;}else{document.form1['textFilename'].disabled=false;}" enctype="multipart/form-data">
</form>
Copy linkTweet thisAlerts:
@jogolauthorSep 02.2008 — Thanks for your help Fang!
×

Success!

Help @jogol 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.1,
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,
)...