Hi Dave,
parseInt converts string to integer.
true is a boolean.
that should be a possibility:
var intVal = undefined;
var boolVal = true;
console.log('intVal: ', intVal)
console.log('boolVal: ', boolVal)
// you only need this line. the rest is to see what happens in FireBug
intVal = (boolVal)? 1:0;
console.log('intVal: ', intVal)
http://www.w3schools.com/JS/js_comparisons.asp -> Conditional Operator
or search for "javascript conditional"
-m
On Aug 11, 6:35 am, Dave Parker <[email protected]> wrote:
> I'm trying to do some math using checkbox generated field values.
> Using <<wikiCalc>> doesn't work:
>
> {{{
> [_(one@)] one
> [_(two@)] two
> [_(three@)] three
> [_(four@)] four
> [_(five@)] five
>
> your score is <<wikiCalc "0+(%1*1)+(%2*1)+(%3*1)+(%4*1)+(%5*1)" "one@"
> "two@" "three@" "four@" "five@">>
> 1+3 is <<wikiCalc "1+3">>
>
> }}}
>
> the above returns:
> your score is Error in macro <<wikiCalc>>
> 1+3 is 4
>
> presumably because the field values are true/false, not 1/0
>
> using this:
> {{{
> <script>
> var one=(store.getValue(tiddler,"one"))
> var one2=parseInt(store.getValue(tiddler,"one"))
> return one
> return one2
> </script>
>
> }}}
>
> gives the "true" when checked and "false" when not, but the
> parseInt(...) doesn't convert it to 1/0 (its just blank)
>
> Is there a straightforward way to use checkbox generated field values
> to do simple math, or do I need some fancier scripting?
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/tiddlywiki?hl=en.