Replicate textbox value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Scheer

    Replicate textbox value

    Hi.

    I have a form with some textboxes in it. When a user clicks a button,
    I need to verify if only one of the textboxes if filled and if so, I
    need to replicate the value of this textbox to all other textboxes on
    the form. If two or more textboxes are filled I don't need to do the
    replication. How can I do that?

    Thanks,

    Robert Scheer
  • Vjekoslav Begovic

    #2
    Re: Replicate textbox value

    Here is sample code to do that:

    <html>
    <head>
    <script language="JavaS cript" type="text/javascript">
    <!--
    function checkForm1(call erValue){
    if (howManyFilled( ) == 1)
    fillAll(callerV alue)
    }

    function fillAll(value){
    for (var i=0; i < document.forms['form1'].elements.lengt h; i++){
    document.forms['form1'].elements[i].value = value;
    }
    }

    function howManyFilled() {
    var howmany = 0;
    for (var i=0; i < document.forms['form1'].elements.lengt h; i++){
    if (document.forms['form1'].elements[i].value == "")
    continue
    howmany++
    }
    return (howmany);
    }
    //-->
    </script>
    </head>

    <body>
    <form name="form1">
    <input type="text" name="textbox1" onchange="check Form1(this.valu e)"><br>
    <input type="text" name="textbox2" onchange="check Form1(this.valu e)"><br>
    <input type="text" name="textbox3" onchange="check Form1(this.valu e)"><br>
    <input type="text" name="textbox4" onchange="check Form1(this.valu e)"><br>
    <input type="text" name="textbox5" onchange="check Form1(this.valu e)"><br>
    <input type="text" name="textbox6" onchange="check Form1(this.valu e)"><br>
    <input type="text" name="textbox7" onchange="check Form1(this.valu e)"><br>
    <input type="text" name="textbox8" onchange="check Form1(this.valu e)"><br>
    </form>
    </body>
    </html>

    "Robert Scheer" <rbscheer@my-deja.com> wrote in message
    news:cfd22ab6.0 307071015.713d2 89b@posting.goo gle.com...[color=blue]
    > Hi.
    >
    > I have a form with some textboxes in it. When a user clicks a button,
    > I need to verify if only one of the textboxes if filled and if so, I
    > need to replicate the value of this textbox to all other textboxes on
    > the form. If two or more textboxes are filled I don't need to do the
    > replication. How can I do that?
    >
    > Thanks,
    >
    > Robert Scheer[/color]


    Comment

    Working...