/    Sign up×
Community /Pin to ProfileBookmark

Disable/Enable Text Fields via a Dropdown?

Hello:

I have 4 single line text fields preceeded by a drop-down form field. By default, I want the text fields disabled, UNLESS, the user makes a selection from the drop-down? Can this be done, especially so without refreshing the page?

For an example of where I want to use this, look at the ‘optional backside engraving’ fields on the page in the link below. Ex. if a user chooses ‘2 Lines of Backside Engraving’ we only want the first 2 text fields to be editable? Thanks for ANY help…

[url]http://www.tagxpress.com/Dog_Bones.htm[/url]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@PittimannJun 20.2004 — Hi!

Three things:

1) In your javascript in the head add this function:[code=php]function showHideTextfield(selIndex,frm){
for (var i=0;i<=3;i++){
if(selIndex<=i){
frm['p1'+i].disabled=true;
}
else{
frm['p1'+i].disabled=false;
}
}
}[/code]


2) Modify the select tag (the opening one) like this:

<select name="p9" onchange="showHideTextfield(this.selectedIndex,this.form)">

3) Add disabled to the four text inputs to have them initially disabled. Example for the first one:

<input type=text name="p10" size="20" maxlength="22" disabled>

And there you are...

Cheers - Pit
Copy linkTweet thisAlerts:
@luckysignsauthorJun 22.2004 — Hello Pit (Pittimann)

Thanks so much for your help with my disabled fields!

I tried to implement the modifications you recommended on the following test page, but am still having some kind of problem?

http://www.tagxpress.com/disabledfieldtest.htm

The fields are disabled, but they don't 'activate' after making a selection from the drop-down preceeding the disabled text fields? Of course this only relates to the 'backside info' fields.

BTW, locally after adding the changes, I get an error on line '43'? Perhaps I have gotten the script wrong that was added to the <head> section? I think you state it's .php? I tried it with/without the JS tags to no avail ? Naturally I am novice, but if this is php-based, wouldn't I have another file

Thanks for any help with this and feel free to email me directly at [email][email protected][/email] anytime if that's easier?

Regards, LS
Copy linkTweet thisAlerts:
@luckysignsauthorJun 22.2004 — Hi Pit

Thanks to your fantastic advice...I got this disabled/enabled dropdown to text field mechanism to work!

My original mistake had to do with the specification of JS tags...what was I thinking??

Anyway, I cannot thank you enough for this - your expertise in this instance is going to be a great help for our site's functionality!

Very Appreciative Regards from the US, LS
Copy linkTweet thisAlerts:
@PittimannJun 22.2004 — Hi!

Sorry, I didn't react to your second last post (5:43 am my local time and I was still sleeping).

You are welcome and I am glad, you got it to work now! ?

Good luck! Regards - Pit
×

Success!

Help @luckysigns 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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