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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complex if condition

Status
Not open for further replies.

greyone

Programmer
Dec 14, 2000
200
CA
hi guys
i have this piece of code which has this complex if else condition which i could'nt understand. Please help

<script>
var _T = &quot;locked&quot;;
var _F = &quot;unlocked&quot;;
function lockIt(_P) {
var _L = document.frmForm.lck.value;
if (_L==_P) return;
document.frmForm.cboSelect.disabled=(document.frmForm.lck.value=(_L==_F)?_T:_F)==_T;

//the last line is what i don't understand

}
 
Hi,

hope this will helps you somehow,

(document.frmForm.lck.value=(_L==_F)?_T:_F) means

if (_L==_F) {
document.frmForm.lck.value = _T;
else
document.frmForm.lck.value = _F;
}

thanks,
Chiu Chan
WebMaster & Software Engineer
emagine solutions, inc
cchan@emagine-solutions.com
 
Thanks for that but what i don't undestand is the condition outside the braces that is ==T thing. Please help

document.frmForm.cboSelect.disabled=(document.frmForm.lck.value=(_L==_F)?_T:_F)==_T;

 
The expression (_L==_F)?_T:_F) is the same as saying

if (_L == _F) then _T else _F

so the entire expression will evaluate to either _T or _F

Because this expression in in parentheses, it will evaluate first. The result will then be assigned to the field frmForm.lck

Once the field has been assigned the value, the field value is compared with the variable _T. This will evaluate to either True of False, which will be the value used to set the disabled property of frmForm.cboSelect.

Any clearer?

It is complicated and there's no &quot;real&quot; need to code it like that :)

Greg.
 
To clarify, it's the same as coding
Code:
var _T = &quot;locked&quot;;
var _F = &quot;unlocked&quot;;
function lockIt(_P) {
  var _L = document.frmForm.lck.value;
  if (_L==_P) return;

  if (_L == _F) {
     document.frmForm.lck.value = _T;
  else
     document.frmForm.lck.value = _F;
  }

  if (document.frmForm.lck.value == _T) {
     document.frmForm.cboSelect.disabled='true';
  else
     document.frmForm.cboSelect.disabled='false';
  }
}

Sorry if there's any bad syntax in there.

Greg.
 
thanks a lot guys that was really helpful
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top