Dr John Stockton wrote in message news:
[email protected]...
Papajo posted:
Consider and adapt
<input type=button value="5"
onClick="javascript:this.value -= this.value>0">
Read the newsgroup FAQ for other matters.
hmmm...
three questions:
1. why the "javascript:" in onClick="javascript:this.value -= this.value>0">
2. if I want to go up, I run into "string" problems:
<input type=text name=amount size=4 value=5>
<input type=button value="down"
onClick="this.form.amount.value -= this.form.amount.value>0">
works wonderfully, but
<input type=button value="up"
onClick="this.form.amount.value += +this.form.amount.value<10">
returns 5true (5truefalse on the next...)
<input type=button value="up"
onClick="this.form.amount.value += +(this.form.amount.value<10)">
returns 51 (and 510 on the second click)
I thought unary+ would type-convert to number, but I notice:
stringVar += +stingVar --> stringVar += numVar
so I end up with
<input type=button value="up"
onClick="this.form.amount.value = +this.form.amount.value + +(this.form.amount.value<10)">
isn't there a shortcut or is type-conversion only really good for - * and /?
ok, came up with the unpretty:
<input type=button value="up"
onClick="this.form.amount.value -= +(this.form.amount.value<10) * -1">
this way, the -= type-converts both sides additionally I need to invert the number (- * - = +)