469,338 Members | 8,638 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

dynamically changing two text fields dependent on each other

Something tells me this is a simple problem, but I seem to be stuck.

I am working on a form in which there are two text fields which can
contain numerical values. But only one of them can have a value other
than zero. So if the first one has a value, the second one becomes
zero, and if you then enter a value in the second one, the first one
reverts to 0.

I didn't create this form originally and so I am working within some
constraints. I won't bore you with the details as to why, but this
can't be a form verification thing where you get a warning when both
fields have a non-zero value. It has to be where if you enter a value
in one, the other becomes 0 and vice versa.

Any suggestions?

Oct 27 '06 #1
4 1474
ASM
toodi4 a écrit :
Something tells me this is a simple problem, but I seem to be stuck.

I am working on a form in which there are two text fields which can
contain numerical values. But only one of them can have a value other
than zero. So if the first one has a value, the second one becomes
zero, and if you then enter a value in the second one, the first one
reverts to 0.
<form>
<input name=one
onkeyup="if(this.value!=0 && this.value!='') two.value=0;">
<input name=two
onkeyup="if(this.value!=0 && this.value!='') one.value=0;">
</form>
Oct 27 '06 #2
Something tells me this is a simple problem, but I seem to be stuck.

I am working on a form in which there are two text fields which can
contain numerical values. But only one of them can have a value other
than zero. So if the first one has a value, the second one becomes
zero, and if you then enter a value in the second one, the first one
reverts to 0.

<form>
<input name=one
onkeyup="if(this.value!=0 && this.value!='') two.value=0;">
<input name=two
onkeyup="if(this.value!=0 && this.value!='') one.value=0;">
</form>
Thanks. I knew it was something simple.

Oct 27 '06 #3

ASM wrote:
toodi4 a écrit :
Something tells me this is a simple problem, but I seem to be stuck.

I am working on a form in which there are two text fields which can
contain numerical values. But only one of them can have a value other
than zero. So if the first one has a value, the second one becomes
zero, and if you then enter a value in the second one, the first one
reverts to 0.

<form>
<input name=one
onkeyup="if(this.value!=0 && this.value!='') two.value=0;">

You shouldn't assume that the unqualified identifier "two" will be
resolved as a control within the form. The above (and the following
script snippet) would be safer as:

onkeyup="if(this.value!=0 && this.value!='')
this.form.two.value=0;">

--
Rob

Oct 27 '06 #4
ASM
RobG a écrit :
ASM wrote:
><form>
<input name=one
onkeyup="if(this.value!=0 && this.value!='') two.value=0;">

You shouldn't assume that the unqualified identifier "two" will be
resolved as a control within the form.
that was working with my NC4 in the last century
so ..
it yet has to work everywhere !
if not : bad browser, to change browser !
The above (and the following
script snippet) would be safer as:

onkeyup="if(this.value!=0 && this.value!='')
this.form.two.value=0;">
Yes, but so much longer (taller, bigger, larger, ...)

Cordially
--
ASM
Oct 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Paul Kooistra | last post: by
10 posts views Thread by Free-Ed, Ltd. | last post: by
9 posts views Thread by Paul Morrow | last post: by
8 posts views Thread by Donald Xie | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.