Convert Boolean to Numeric

P

Pachydermitis

Hi all,
This has got to be easy, but it's got me going bald.
How do I convert a Boolean to a numberic value? This value is going
to a hidden field that is going to an SQL server. There has to be an
elegant way to change true to 1 and false to 0.
Thanks
Pachydermitis
 
K

kaeli

Hi all,
This has got to be easy, but it's got me going bald.
How do I convert a Boolean to a numberic value? This value is going
to a hidden field that is going to an SQL server. There has to be an
elegant way to change true to 1 and false to 0.
Thanks
Pachydermitis

var b = true;
var x= b?1:0;


-------------------------------------------------
~kaeli~
All I ask for is the chance to prove that money
cannot make me happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
V

VK

JavaScript is not Java, its casting syntax is narrowed.
As 'kaeli' said, the simplest is:
myElement.value = (x)?1:0;
And what is not elegant in this?
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
JavaScript is not Java, its casting syntax is narrowed.
As 'kaeli' said, the simplest is:
myElement.value = (x)?1:0;
And what is not elegant in this?

Since +x will do the conversion, your method is tediously long-winded
and untidy. It is certainly not simplest.

Please read the weekly-posted FAQ on the composition of news replies; in
particular on the desirability of trimming quotes and answering after.

Look at the posts in this group; to avoid possible prejudice, omit yours
and mine. You will soon see that the more competent posters use the
form recommended in the FAQ; and, ISTM, that such posters get better
replies, if they need help.
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top