Krupski
November 12th, 2010, 05:34 AM
NOTE: This is not homework and I am not a student.
Hi all,
Simple question: Is it possible to put several expressions inside a single condition when using the ternary operator in Javascript?
Normally, it's done like this:
a=10 ? a=20 : a=10;
But, what I want to do is this:
a=10 ? (a=20; b='Twenty') : (a=10, b='Ten');
See? I want to do TWO (or more) things for each condition. Is this possible in Javascript? And if so, how to do it?
The actual use for this is:
/**
* Toggle WYSIWYG / textarea
**/
function toggle(a)
{
var e = tinyMCE.get('message'); /* editor */
e.isHidden() ? e.show() : e.hide(); /* toggle show/hide */
e.isHidden() ? a.value = 'WYSIWYG' : a.value = 'Textarea'; /* toggle button label */
}
...which is called by this:
<input type="button" value="Textarea" class="button2" onclick="toggle(this);" />
What I hope to do is use only one ternary line and set BOTH "show/hide" AND "wysiwyg/textarea" at the same time.
Possible?
Thanks!
-- Roger
Hi all,
Simple question: Is it possible to put several expressions inside a single condition when using the ternary operator in Javascript?
Normally, it's done like this:
a=10 ? a=20 : a=10;
But, what I want to do is this:
a=10 ? (a=20; b='Twenty') : (a=10, b='Ten');
See? I want to do TWO (or more) things for each condition. Is this possible in Javascript? And if so, how to do it?
The actual use for this is:
/**
* Toggle WYSIWYG / textarea
**/
function toggle(a)
{
var e = tinyMCE.get('message'); /* editor */
e.isHidden() ? e.show() : e.hide(); /* toggle show/hide */
e.isHidden() ? a.value = 'WYSIWYG' : a.value = 'Textarea'; /* toggle button label */
}
...which is called by this:
<input type="button" value="Textarea" class="button2" onclick="toggle(this);" />
What I hope to do is use only one ternary line and set BOTH "show/hide" AND "wysiwyg/textarea" at the same time.
Possible?
Thanks!
-- Roger