dynamically changing two text fields dependent on each other

Discussion in 'Javascript' started by toodi4, Oct 27, 2006.

  1. toodi4

    toodi4 Guest

    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?
     
    toodi4, Oct 27, 2006
    #1
    1. Advertising

  2. toodi4

    ASM Guest

    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>
     
    ASM, Oct 27, 2006
    #2
    1. Advertising

  3. toodi4

    toodi4 Guest

    > > 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.
     
    toodi4, Oct 27, 2006
    #3
  4. toodi4

    RobG Guest

    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
     
    RobG, Oct 28, 2006
    #4
  5. toodi4

    ASM Guest

    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
     
    ASM, Oct 28, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pete.....

    tags dependent on each other ?

    Pete....., Mar 24, 2005, in forum: HTML
    Replies:
    1
    Views:
    413
    Toby Inkster
    Mar 25, 2005
  2. Kent
    Replies:
    2
    Views:
    3,430
    Derek
    Dec 23, 2003
  3. Andy
    Replies:
    2
    Views:
    343
  4. puzzlecracker
    Replies:
    1
    Views:
    546
    James Kanze
    Aug 7, 2008
  5. middletree

    how to copy from fields to other fields

    middletree, Nov 5, 2003, in forum: ASP General
    Replies:
    1
    Views:
    184
    middletree
    Nov 5, 2003
Loading...

Share This Page