Disable a textbox by reference

D

Daniel

Hello,

I'm trying to enable/disable a textbox by reference but seem to be
having a great deal of trouble.

function enableField(EleName,EleVal)
{
// All controls in form 'usrsel'
// EleName = Name of the control to be disabled
// EleVal = Comparison string, value from the select control
alert("The control id is: " + EleName + " " + EleVal)

If (EleVal == 'Other')
{
document.usrsel.getElementsByName(EleName).disabled=false;
}
else
{
document.usrsel.getElementsByName(EleName).disabled=false;
}
}

The issue is I place the alert statement for troubleshooting. it work
and returns the value I send from the onchange event. However, The If
stament does not seem to trigger. Could someone help me get this
functional.

Thank you

Daniel
 
D

Daniel

@o61g2000hsh.googlegroups.com:




is it because the "else" above is identical to the "if"? :)

me thinks one of them should be ".disabled = true;"

You are right about that, but it still doesn't work with that change.

function enableField(EleName,EleVal)
{
If (EleVal == 'Other')
{
document.usrsel.getElementsByName(EleName).disabled=false;
} else {
document.usrsel.getElementsByName(EleName).disabled=true;
}
}
 
D

Daniel

You are right about that, but it still doesn't work with that change.

function enableField(EleName,EleVal)
{
If (EleVal == 'Other')
{
document.usrsel.getElementsByName(EleName).disabled=false;
} else {
document.usrsel.getElementsByName(EleName).disabled=true;
}
}- Hide quoted text -

- Show quoted text -

What is even weirder is the following does not work either

function enableField(EleName,EleVal)
{
alert(EleName + " " + EleVal);
If (EleVal == 'Other') alert("The value is Other");
}

The first alerts works fine and return the proper values including the
fact that EleVal=Other, but the If statement does not trigger the 2nd
alert???

Ca someone explain what it is that I've done wrong.

Thank you,

Dnaiel
 
E

ED

Daniel said:
What is even weirder is the following does not work either

function enableField(EleName,EleVal)
{
alert(EleName + " " + EleVal);
If (EleVal == 'Other') alert("The value is Other");
}

The first alerts works fine and return the proper values including the
fact that EleVal=Other, but the If statement does not trigger the 2nd
alert???

Ca someone explain what it is that I've done wrong.

Thank you,

Dnaiel

um, case sensitivity?

try:
if (EleVal == 'Other') alert("The value is Other");
not
If (EleVal == 'Other') alert("The value is Other");

cheers
ED
 
D

Daniel

Could the problem be that the "If" should be "if"?








- Show quoted text -- Hide quoted text -

- Show quoted text -

I think you may be right. I'm new to javascripting and didn't realize
that it was case sensitive!

Thanks for the help!
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
is it because the "else" above is identical to the "if"? :)

me thinks one of them should be ".disabled = true;"

No,

The code should be (where == may need to be !=)

document.usrsel.getElementsByName(EleName).disabled = EleVal == 'Other'

And then there's no IF to get the case wrong of. Additional parentheses
optional.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top