Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    uk
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    slight problem with this script

    i use the following script to make any spaces at the start or end of a form field to be deleted when the focus goes out of the form field. the only problem is if the person presses enter to submit the form, it doesnt remove the spaces for the field they are in. can anyone modify this script to fix this problem? thanks a lot, paul

    heres the script:

    function trimtext(txt) {
    var temptext=txt.value.replace(/\s*/,'');
    ets = temptext.substring(temptext.length-1, temptext.length);
    while(ets==" ") {
    temptext = temptext.substring(0, temptext.length-1);
    ets = temptext.substring(temptext.length-1, temptext.length); }
    txt.value = temptext; }

    <input type="text" onchange="trimtext(this)">

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could call the function onSubmit of the form.

    <form name=temp method=post action=mypage.html onSubmit="trimtext('document.temp.textAreaName')">


    That way it is called when the user hit's enter, and the browser begins to submit the form.

    ShriekForth


  •  

    Posting Permissions

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