lot of nulls

J

jamuna

setInterval('with(document.form)pole.value = pole2.value*wynik.value',200)
it returns me some big number with a lot of nulls after point.
how to .... it?
 
D

DJ WIce

: setInterval('with(document.form)pole.value = pole2.value*wynik.value',200)
: it returns me some big number with a lot of nulls after point.
: how to .... it?

eval(math.power(wynik.value,x)*pole2.value);
 
R

Richard Cornford

DJ WIce said:
: setInterval('with(document.form)pole.value = pole2.value*wynik.value'
:,200)
: it returns me some big number with a lot of nulls after point.
: how to .... it?

eval(math.power(wynik.value,x)*pole2.value);

Is that a joke?

Richard.
 
D

DJ WIce

: >: setInterval('with(document.form)pole.value = pole2.value*wynik.value'
: >:,200)
: >: it returns me some big number with a lot of nulls after point.
: >: how to .... it?
: >
: > eval(math.power(wynik.value,x)*pole2.value);
:
: Is that a joke?

sorry, I did misread. I did not see that it was pole.value = indead of
pole2.value =
my mistake.

Wouter
 
R

Richard Cornford

DJ WIce said:
:>:setInterval('with(document.form)pole.value = pole2.value*
:>:wynik.value',200)
:>:it returns me some big number with a lot of nulls after point.
:>:how to .... it?

<URL: http://jibbering.com/faq/#FAQ4_7 >
And so:-
<URL: http://jibbering.com/faq/#FAQ4_6 >

Maybe with:-
:>
:>eval(math.power(wynik.value,x)*pole2.value);
:
:Is that a joke?

sorry, I did misread. I did not see that it was pole.value =
indead of pole2.value =
my mistake.

You only recognise the one mistake?

Richard.
 
L

Lasse Reichstein Nielsen

jamuna said:
setInterval('with(document.form)pole.value = pole2.value*wynik.value',200)
it returns me some big number with a lot of nulls after point.
how to .... it?

Code is *not* obvious, especially when you say that it is not doing
what you want ... so: What are you trying to do?

Also, if we can't reproduce the problem, it's hard to know when it is
fixed. What numbers have you entered into the form controls pole2 and
wynik?

My *guess* is that you want to keep one form cell's value updated with
the multiplum of two other cells' values. How many decimals do you
want?

There are several promblems with the method you use:

1) Addressing form controls. For consistent access to forms across
browsers, and also compliance with W3C DOM, you should use the
collections document.forms and form.elements.
So:
with(document.forms['form']) {
elements.pole.value = elements.pole2.value * elements.wynik.value;
}

2) Personally, I wouldn't use "with". Just do:
var elems = document.forms['form'].elements;
elems.pole.value = elems.pole2.value * elems.wynik.value;"

3) It's inefficient to constantly change the content of the "pole"
control. You can trigger the recalculation only when you have changed
on of the other controls.

My suggestion:

<script type="text/javascript">
function recalc(form) {
var elems = form.elements;
elems['pole'].value =
Math.round(elems['pole2'].value * elems['wynik'].value);
// ^^^^^ rounds to nearest integer, so no more zeroes.
}
</script>
</script>
<form ...>...
<input name="pole">...
<input name="pole2" onchange="recalc(this);">...
<input name="wynik" onchange="recalc(this);">...
</form>

Good luck
/L
 
D

DJ WIce

: <input name="pole2" onchange="recalc(this);">...
: <input name="wynik" onchange="recalc(this);">...

Maybe onkeyup or something because in IE onchange is only triggered when the
field loses focus.

Wouter
 
L

Lasse Reichstein Nielsen

DJ WIce said:
: <input name="pole2" onchange="recalc(this);">...
: <input name="wynik" onchange="recalc(this);">...

Maybe onkeyup or something because in IE onchange is only triggered when the
field loses focus.

True (as in all other browsers). However, I consider that an advantage.
Let the user type in peace, and calculate when he is done, instead of
having some other field change while he is typing.

/L
 
D

DJ WIce

: > Maybe onkeyup or something because in IE onchange is only triggered when
the
: > field loses focus.
:
: True (as in all other browsers). However, I consider that an advantage.
: Let the user type in peace, and calculate when he is done, instead of
: having some other field change while he is typing.

Well, like is done in http://www.mattkruse.com/javascript/autocomplete/ I
don't mind if some things change (altrough it's here in the same box I'm
typing in). As long as I can type trough without change of my input (like in
the linked script).

Wouter
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top