Link to home
Create AccountLog in
Avatar of babak62
babak62

asked on

trim spaces in textbox

Hi;
This is my form and I need to trim the spaces client side also no spaces on the left or right onblur.  Here is my form

            <input type="text" name="keyword" value=""   onblur=""/>
           <input type="submit" name="submit" value="Search!" />
         <p>Enter your search terms. Boolean operators are supported.</p>
        </p></form>
Would you please tell me where and what code should I use for this?  Thanks a lot for the help.
Avatar of s_chilkury
s_chilkury
Flag of United States of America image

onblur="trimText(this)"

//javascript to trim spaces
function trimText(textBox)  
{      
          var textValue = textBox.value;
          textValue = textValue.replace(/(\s+$)|(^\s+)/g, '');
          textBox.value = textValue;
}
Avatar of babak62
babak62

ASKER

thanks a lot can you please tell me how I should place the call in my form?
ASKER CERTIFIED SOLUTION
Avatar of s_chilkury
s_chilkury
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of babak62

ASKER

PERFECT and thanks a lot for the great help