Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

else if statement

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
Hello,

I have a JavaScript that checks if the field is not empty it dissables the field. I was trying to modify my code to enable the field depending on the response given in another field.

Here is what I have so far

original code
Code:
var var33= Runner.getControl(pageid,'resp'); 
var var34= Runner.getControl(pageid,'explain');
var var35= Runner.getControl(pageid,'iscontroldocumented'); 
var var36= Runner.getControl(pageid,'narrativeofcontrol'); 
var var37= Runner.getControl(pageid,'frequency'); 
var var38= Runner.getControl(pageid,'personresponsable'); 
var var39= Runner.getControl(pageid,'manualorautomated'); 
var var55= Runner.getControl(pageid,'correctiveactionplanned'); 
var var50 = Runner.getControl(pageid, 'plancompletiondate'); 
var var58 = Runner.getControl(pageid, 'Status');


if (var50.getValue() != ''){
var50.setDisabled();
var55.setDisabled(); 
var33.setDisabled(); 
var34.setDisabled(); 
var35.setDisabled(); 
var36.setDisabled(); 
var37.setDisabled(); 
var38.setDisabled(); 
var39.setDisabled(); 


}

this is what I added

Code:
else if (var58.getvalue()=='No'){
var50.setEnabled();
var55.setEnabled(); 
var33.setEnabled(); 
var34.setEnabled(); 
var35.setEnabled(); 
var36.setEnabled(); 
var37.setEnabled(); 
var38.setEnabled(); 
var39.setEnabled();  
}
adding the code above makes my fields editable no matter what

not sure what I am doing wrong.

any help is much appreciated

Thanks!!!
 
Not sure what to tell you other than var58's value is apparently always set to No then. So your other items are enabled always. This of course overrides the previous if.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thank you Phil!!

I see what you are saying, I tried

Code:
else if ((var58.getvalue()=='No')&&(var39.getValue() != '')){
var50.setEnabled();
var55.setEnabled(); 
var33.setEnabled(); 
var34.setEnabled(); 
var35.setEnabled(); 
var36.setEnabled(); 
var37.setEnabled(); 
var38.setEnabled(); 
var39.setEnabled();  
}

but that did not work either.

I think I might be going the wrong way about the whole thing.

if my "status" field is equal to "Yes" then all the var should be dissabled, but if the status field = "No"
then the var shou be enabled

could it be as simple as???

Code:
if (var58.getvalue()=='Yes'){
var50.setDisabled();
var55.setDisabled(); 
var33.setDisabled(); 
var34.setDisabled(); 
var35.setDisabled(); 
var36.setDisabled(); 
var37.setDisabled(); 
var38.setDisabled(); 
var39.setDisabled();  
}
else if (var58.getvalue()=='No'){
var50.setEnabled();
var55.setEnabled(); 
var33.setEnabled(); 
var34.setEnabled(); 
var35.setEnabled(); 
var36.setEnabled(); 
var37.setEnabled(); 
var38.setEnabled(); 
var39.setEnabled();  
}
 
nope not that simple that did not work at all,
if my "status" field = "Yes" all the other fields are editable and if the "status" field ="No" all the other fields are still editable... hmmmmm
 
1. I'm assuming all your elements start off as enabled by default.

2. You were checking var50 and now you want to check var58?

Anyway what happens when its neither of those values? What happens when var58 is "maybe" or something else like maybe 'yes' in lower case instead of the uppercase Y. It won't fall into any of those 2 so it does nothing. If we take assumption 1. then the elements will remain enabled.

In any case, first thing would be to check that your vars have the value you expect.

Second is to make sure you have no errors that may be stopping this code from running.

At the end yes if your variables have the expected values, then the checking is simple:

Code:
if(var58.getValue=="Yes"){
**disabled**
}
elseif (var58.getValue=="No"){
**enabled**
}



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top