SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove spaces at the beginning of the text box

    Hi All,

    I am using the following code to remove white spaces at the beginning of txt box.if i change textbox name it doesnot work.

    Please Someone help.

    Code JavaScript:
    <script>
    //Javascript
    function white_space(field)
    {
         field.value = (field.value).replace(/^\s*/g,'');
    }
    </script>
     
    //example HTML
    <form action="" method="get" name="test_form">
         <input type="text"   name="text"  onKeyPress="white_space(text)"  />
         <input type="button" name="button" value="button" />
    </form>

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    function white_space(field)
    {
         field.value = field.value.replace(/^\s+/, "");
    }

    Code HTML4Strict:
    <form action="" method="get">
      <div>
         <input type="text" name="text"  onkeypress="white_space(this)">
         <input type="button" name="button" value="button">
      </div>
    </form>
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •