Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > dynamically changing two text fields dependent on each other

Reply
Thread Tools

dynamically changing two text fields dependent on each other

 
 
toodi4
Guest
Posts: n/a
 
      10-27-2006
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?

 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      10-27-2006
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>
 
Reply With Quote
 
 
 
 
toodi4
Guest
Posts: n/a
 
      10-27-2006
> > 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.

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      10-27-2006

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

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      10-28-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
non-dependent vs. dependent template names puzzlecracker C++ 1 08-07-2008 07:42 AM
how shall I reload several obejcts that dependent on each other? Andy C++ 2 05-06-2005 10:13 PM
tags dependent on each other ? Pete..... HTML 1 03-25-2005 10:37 AM
Two classes dependent on each other, generating "syntax error: identifier 'NAME' " Kent C++ 2 12-23-2003 07:47 PM
how to copy from fields to other fields middletree ASP General 1 11-05-2003 06:24 PM



Advertisments