Re: JS Arithmetic

Tech-Archive recommends: Speed Up your PC by fixing your registry



Roland,
Thank you so much

It is great to get a reference to the details of Javascript. If only there
were a single source that covered the entire language with the right amount
of detail. The reference you gave looks good. I can see that the unary
operator does involve a function call.

I have implemented all of your suggetsions. My code now reads:
<form onsubmit="chgImg(+no.value + 1000)">
....
<input id="no" name="no" type="text" value="" maxlength="3" size="1">
<input type="submit" value="Go">
</form>

This is very succinct and works beautifully :-D
Although I wonder which of the two (id="no" name="no") is referenced by
onsubmit=
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

Roland Hall wrote:
> "Trevor L." wrote in message
> news:ePA%23RuLOFHA.440@xxxxxxxxxxxxxxxxxxxxxxx
>> Thank you all
>>
>> I like this solution
>> onclick="document.write(+(this.form['no'].value) + 1000)">
>> It doesn't need any functions such as parseInt and avoids the 08/09
>> problem
>
> Don't think it doesn't perform functions:
> http://xkr.us/articles/javascript/unary-add/
>
> Two comments on your solution:
>
> 1. you don't need 'this'.
> 2. Since you're using button instead of submit, if you put in the
> number and press ENTER, it doesn't work.
>
> It works with either keypress or onclick if you use submit and put it
> in the onsubmit but then you don't need to reference the element as a
> form element.
>
> no.value is sufficient.
>
> You also do not need ( )
>
> http://kiddanger.com/lab/forms1.html


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html


.


Quantcast