...

View Full Version : Disable field via Drop Down Selection



fncuis
11-08-2004, 09:38 PM
While I am here... I have one more inquiry.

http://www.hcedesigns.com/spec.html

Spa Shape Option in the form.
To be exact its: "If yes, what shape would you prefer?"

There are several options in the drop down for selecting a spa shape. Below it are the dimensions for the spa shape. The only two that can have the diameter option enabled are "half-circle" & "circle".

I have the diameter field disabled by default. How do i specify enable when one of the two aforementioned spa shapes is chosen?

Thanks!

Willy Duitt
11-09-2004, 01:25 AM
Try this:



<select name="shape" class="txtFields" id="shape"
onchange="if(this.value.match(/Circle$/gi))
{this.form.spadiameter.disabled=0}else
{this.form.spadiameter.disabled=1}">


.....Willy

fncuis
11-09-2004, 01:08 PM
He Willy...

I am a bit a of a newb with this stuff.. could you show me where in my code that goes? Or just paste the code above and below yours?

THanks,

fncuis
11-09-2004, 01:34 PM
Actually!

It works! I just copied the onchange portion of it and inserted into the select string. Works like a charm! Thank you very much!

So that I learn, could you please translate this portion to english?

if(this.value.match(/Circle$/gi)

Thanks,

-F

Willy Duitt
11-09-2004, 03:16 PM
It merely checks if the end of the selected option value matches the word circle... It does not mater if it is: circle, half-circle, semi circle or decircle (case insensitive)....

.....Willy

fncuis
11-09-2004, 04:25 PM
Well come to find out, not only should it enable it upon selection, but it should also disable the width & length fields simultaneously.

Going to do some research first before I wave my white flag.

See yeah and thanks for the help!

Willy Duitt
11-09-2004, 04:54 PM
Hint: 0 is false; 1 is true...

fncuis
11-09-2004, 06:32 PM
<select name="shape" class="txtFields" id="shape" onchange="if(this.value.match(/Circle$/gi))
{this.form.spadiameter.disabled=0}else{this.form.spadiameter.disabled=1}">

Ok above is the string you gave me, but i cant find anything that allows me to target multiple field elements on the same string.

I tried using:

<select name="shape" class="txtFields" id="shape" onchange="if(this.value.match(/Circle$/gi))
{this.form.spadiameter.disabled=0}else{this.form.spadiameter.disabled=1}and{this.form.spawidth.disab led=0">

But that didnt work, and i also didnt know how to add the final piece to also disable the spalength.

Help!

Willy Duitt
11-09-2004, 07:04 PM
There's several ways to do this...
Here is one way which assigns the disabled value of one input to the disabled value of another which is ultimately assigned a value of true or false...



<select name="shape" class="txtFields" id="shape"
onchange="if(this.value.match(/Circle$/gi))
{this.form.spadiameter.disabled=this.form.spawidth.disabled=this.form.spalength.disabled=0}else
{this.form.spadiameter.disabled=this.form.spawidth.disabled=this.form.spalength.disabled=1}">


.....Willy

fncuis
11-09-2004, 07:15 PM
Im following you with this... i think :P

Can i add more arguments by simply adding "=" in the statement?

Example below:

<select name="shape" class="txtFields" id="shape"
onchange="if(this.value.match(/Circle$/gi))
{this.form.spadiameter.disabled=this.form.spalength.disabled=this.form.spawidth.disabled=0}else
{this.form.spadiameter.disabled=this.form.spalength.disabled=this.form.spawidth.disabled=1}
">

fncuis
11-09-2004, 07:16 PM
Actually, that disables the length, width, and diameter... unless you are on circle.

Follow?

Willy Duitt
11-09-2004, 07:21 PM
no hablo....

Oh, if you are wanting to disable other fields while enabling the spadiameter... just add another line to both the if and the else conditionals (between the curly braces { <--->}) and assign a value of 1 if spadiameter is 0 and 0 if spadiameter is 1....

fncuis
11-09-2004, 08:20 PM
Ok, i got this to work, but there is one problem:

<select name="shape" class="txtFields" id="shape" onchange="if(this.value.match(/Circle$/gi))
{this.form.spadiameter.disabled=0}else{this.form.spadiameter.disabled=1}
if(this.value.match(/Circle$/gi)){this.form.spawidth.disabled=1}
if(this.value.match(/Circle$/gi)){this.form.spalength.disabled=1}">

When you "reselect" one of the previous options, it doesnt reenable the fields...? Any ideas?

fncuis
11-09-2004, 08:23 PM
duh.. forgot the }else{

...lol



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum