auto fill in number of letters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yoshimishu
    New Member
    • Feb 2008
    • 29

    auto fill in number of letters

    i have to create two text boxes. If i fill in first text box the second textbox shoud automatically display the number of letters displayed in first text box. If the number of letters in first text box reaches 10 then an alert shoud show up saying too long. and both the text boxes shoul be reset.
    [CODE=javascript]<html>
    <head>
    <Script language="JavaS cript">
    function alll()
    {

    if(document.for ms[0].elements[0].value.length < 10)
    {
    document.forms[0].elements[1].vaule=document .forms[0].elements[0].value.length;
    }
    if(document.for ms[0].elements[0].value.length>= 10)
    {
    alert("too"+'\n '+"long");
    }
    }
    </Script>
    </head>
    <body>
    <form name = "f1">Enter your Message (Max is 10 characters) :
    <input type = "Textbox" name = "t1" onfocus="alll() "><br>
    Here is the Amount you entered &nbsp; &nbsp;:
    <input type = "Textbox" name = "t2"></form>
    </body>
    </html>

    [/CODE]
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    So what doesn't work?

    On line 9, you have a typo: "vaule" instead of "value".

    Comment

    • yoshimishu
      New Member
      • Feb 2008
      • 29

      #3
      Originally posted by acoder
      So what doesn't work?

      On line 9, you have a typo: "vaule" instead of "value".
      the value in second textbox is updating when i again get the focus of first window. can't the value of second textbox change at same time as I am filling the text in first textbox.

      Is there some method for it.

      Thanks.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        [CODE=javascript]function alll() {
        if (document.forms[0].elements[0].value.length < 10) {
        document.forms[0].elements[1].value = document.forms[0].elements[0].value.length;
        }
        if (document.forms[0].elements[0].value.length>= 10) {
        alert("too"+'\n '+"long");
        document.forms[0].elements[0].value = '';
        document.forms[0].elements[1].value = '0';
        }
        }[/CODE][html]<input type = "Textbox" name = "t1" onkeyup="alll() ">[/html]

        Comment

        • yoshimishu
          New Member
          • Feb 2008
          • 29

          #5
          Originally posted by hsriat
          [CODE=javascript]function alll() {
          if (document.forms[0].elements[0].value.length < 10) {
          document.forms[0].elements[1].value = document.forms[0].elements[0].value.length;
          }
          if (document.forms[0].elements[0].value.length>= 10) {
          alert("too"+'\n '+"long");
          document.forms[0].elements[0].value = '';
          document.forms[0].elements[1].value = '0';
          }
          }[/CODE][html]<input type = "Textbox" name = "t1" onkeyup="alll() ">[/html]
          Thanks man it is working now.

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Originally posted by yoshimishu
            Thanks man it is working now.
            Glad to know that :)

            Post again for another problem.

            - HSRiat

            Comment

            Working...