Is there a way to keep 2 textboxes the same???

Discussion in 'Javascript' started by lewis_t@mittalsteel.com, Jan 20, 2006.

  1. Guest

    Is there a way have 2 textboxes on the same form where the value of the
    first textbox is always the value of the 2nd textbox (even onload)?
     
    , Jan 20, 2006
    #1
    1. Advertising

  2. Evertjan. Guest

    wrote on 20 jan 2006 in comp.lang.javascript:

    > Is there a way have 2 textboxes on the same form where the value of the
    > first textbox is always the value of the 2nd textbox (even onload)?


    <input id=t1
    onkeyup='document.getElementById("t2").value=this.value'>
    <br>
    <input id=t2
    onkeyup='document.getElementById("t1").value=this.value'>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jan 20, 2006
    #2
    1. Advertising

  3. Guest

    Thank you very much for your reply.

    Will the onkeyup event get triggered onload?
     
    , Jan 20, 2006
    #3
  4. Evertjan. Guest

    wrote on 20 jan 2006 in comp.lang.javascript:

    > Thank you very much for your reply.
    >
    > Will the onkeyup event get triggered onload?
    >


    No, but why should you?

    At load time both <input's are empty,

    or you van fill them with the same value, like:

    <input value='blah'>
    <input value='blah'>

    or you can fill both by an onload script:

    <body onload = 'document.getElementById("t1").value=
    document.getElementById("t2").value="blah"'>



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jan 20, 2006
    #4
  5. David Dorward, Jan 20, 2006
    #5
  6. T L Guest

    I didn't really explain what I am trying to accomplish... I have a form
    with a large table displaying values I extract from a database. I want
    to put some final totals from the table at the top of the form (ie:
    number of rows with value x). I would rather not create arrarys or
    loop thru the ADO recordset to calculate these values then go back
    (movefirst) and loop thru again to display. I thought about putting a
    hidden textbox at the bottom of the form that would update the textbox
    at top of the form. Maybe there is a better way to do this?
     
    T L, Jan 20, 2006
    #6
  7. wrote:

    > Is there a way have 2 textboxes on the same form where the value of the
    > first textbox is always the value of the 2nd textbox (even onload)?


    Quickhack:

    <head>
    ...
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function syncInputs(f, name1, name2)
    {
    var es;
    if (f && (es = f.elements)
    && es[name1]
    && es[name2]
    && typeof es[name2].value != "undefined")
    {
    es[name2].value = es[name1].value;
    }
    }
    </script>
    </head>

    <body onload="syncInputs(document.forms['form1'], 'text1', 'text2');">
    ...
    <form ... name="form1">
    <input name="text1" value="foo"
    onchange="syncInputs(this.form, this.name, 'text2');">
    <input name="text2">
    </form>
    ...
    </body>


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jan 20, 2006
    #7
  8. T L wrote:
    ^^^
    Hmmm... :)

    > [...] I have a form with a large table displaying values I extract from a
    > database. I want to put some final totals from the table at the top of
    > the form (ie: number of rows with value x). I would rather not create
    > arrarys or loop thru the ADO recordset to calculate these values then go
    > back (movefirst) and loop thru again to display. I thought about putting
    > a hidden textbox at the bottom of the form that would update the textbox
    > at top of the form. Maybe there is a better way to do this?


    I have not used ADO much recently, but I think you want to do a query and
    then use the Count property --

    <URL:http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoproperties.asp>

    -- or simply use a variable that you increase as you iterate through the
    recordset.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jan 20, 2006
    #8
  9. T L Guest

    > PointedEars wrote:
    > I have not used ADO much recently, but I think you want to do a query and
    > then use the Count property --
    >
    > <URL:http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoproperties.asp>
    >
    > -- or simply use a variable that you increase as you iterate through the
    > recordset.


    Yes - it is not the total number of rows (so I can't use ADOrs.Count),
    but I have a variable that counts the values of interest. It counts
    these values as it gets them from ADO and builds the HTML to display
    (ASP).
    The problem I am having is when I am done building this HTML table I
    want to update a textbox at the top of the form with some totals.
     
    T L, Jan 20, 2006
    #9
  10. rkc Guest

    T L wrote:
    >>PointedEars wrote:
    >>I have not used ADO much recently, but I think you want to do a query and
    >>then use the Count property --
    >>
    >><URL:http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoproperties.asp>
    >>
    >>-- or simply use a variable that you increase as you iterate through the
    >>recordset.

    >
    >
    > Yes - it is not the total number of rows (so I can't use ADOrs.Count),
    > but I have a variable that counts the values of interest. It counts
    > these values as it gets them from ADO and builds the HTML to display
    > (ASP).
    > The problem I am having is when I am done building this HTML table I
    > want to update a textbox at the top of the form with some totals.


    If the calculations aren't the result of any user action after the
    fact, why don't you just do them using sql on the server?
     
    rkc, Jan 21, 2006
    #10
  11. T L wrote:

    >> PointedEars wrote:
    >> I have not used ADO much recently, but I think you want to do a query and
    >> then use the Count property --
    >>
    >>

    <URL:http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoproperties.asp>
    >>
    >> -- or simply use a variable that you increase as you iterate through the
    >> recordset.

    >
    > Yes - it is not the total number of rows (so I can't use ADOrs.Count),
    > but I have a variable that counts the values of interest. It counts
    > these values as it gets them from ADO and builds the HTML to display
    > (ASP).
    > The problem I am having is when I am done building this HTML table I
    > want to update a textbox at the top of the form with some totals.


    You do not have to generate the HTML code while you iterate the
    recordset, you can concatenate a string that you write later.

    Please provide attribution of quoted material.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jan 23, 2006
    #11
  12. Jasen Betts wrote:

    > On 2006-01-20, T L <> wrote:
    >> Yes - it is not the total number of rows (so I can't use ADOrs.Count),
    >> but I have a variable that counts the values of interest. It counts
    >> these values as it gets them from ADO and builds the HTML to display
    >> (ASP).
    >> The problem I am having is when I am done building this HTML table I
    >> want to update a textbox at the top of the form with some totals.

    >
    > you could put code in your onload to update the top field.


    Following this suggestion would introduce a dependendy on client-side
    scripting and DOM features unnecessarily.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jan 23, 2006
    #12
  13. T L Guest

    Jasen Betts wrote:
    >
    > you could put code in your onload to update the top field.
    >


    I tried to link 2 textboxes together in the onload event, like what
    Pointed Ears suggested without the ="blah" (because I don't know the
    value at that point) but no luck. I assume it is setting textbox 1 to
    texbox 2 but at load time both values are blank.
     
    T L, Jan 24, 2006
    #13
  14. T L Guest

    rkc wrote:
    >
    > If the calculations aren't the result of any user action after the
    > fact, why don't you just do them using sql on the server?


    This is the way it works now. It is using ODBC to a VAX Oracle RDB
    database. To do the calculations is very expensive and I was trying to
    avoid DB hits.
     
    T L, Jan 24, 2006
    #14
  15. T L Guest

    Thomas 'PointedEars' Lahn wrote:
    >
    > You do not have to generate the HTML code while you iterate the
    > recordset, you can concatenate a string that you write later.
    >


    No I don't have to necessarily write the html out while I am iterating
    thru the recordset. It will take a little doing but I can defineately
    do that. Thanks...
     
    T L, Jan 24, 2006
    #15
  16. VK Guest

    T L wrote:
    > I didn't really explain what I am trying to accomplish... I have a form
    > with a large table displaying values I extract from a database. I want
    > to put some final totals from the table at the top of the form (ie:
    > number of rows with value x). I would rather not create arrarys or
    > loop thru the ADO recordset to calculate these values then go back
    > (movefirst) and loop thru again to display. I thought about putting a
    > hidden textbox at the bottom of the form that would update the textbox
    > at top of the form. Maybe there is a better way to do this?


    Why don't you want to use thead and tfoot sections? They are specially
    convenient for large databound tables (unless I'm missing some
    details).

    <table>
    <thead>
    ....
    </thead>
    <tfoot>
    ....
    </tfoot>
    <tbody>
    ....
    </tbody>
    </table>

    P.S. Yes, thead-tfoot-tbody, this is the right standard endorsed
    sequence. You may guess now why ;-)
     
    VK, Jan 24, 2006
    #16
  17. Evertjan. Guest

    VK wrote on 24 jan 2006 in comp.lang.javascript:

    > P.S. Yes, thead-tfoot-tbody, this is the right standard endorsed
    > sequence. You may guess now why ;-)
    >


    Thank you for this allowance.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jan 24, 2006
    #17
    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. Replies:
    1
    Views:
    369
  2. Joshua Beall
    Replies:
    1
    Views:
    473
    Bertilo Wennergren
    Dec 10, 2003
  3. Laura D.
    Replies:
    2
    Views:
    369
    Chris F.A. Johnson
    Oct 8, 2007
  4. Bishop
    Replies:
    14
    Views:
    789
    Gregory A. Beamer
    Jun 19, 2009
  5. hisan
    Replies:
    1
    Views:
    1,406
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page