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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trim text in TEXTAREA

    Have got some code to trim the text of an INPUT text box on a form but it doesn't work for a TEXTAREA.

    The relevant sections of code are:

    *** Repeated for each INPUT box and TEXTAREA.
    // Check for empty subject.
    stripSpaces(enquiry.subject);
    if (isFilled(enquiry.subject) == false) {
    alert("Please enter your subject.");
    enquiry.subject.focus();
    return false;
    }

    // Check for empty question.
    if (isFilled(enquiry.message) == false) {
    alert("Please enter your question.");
    enquiry.message.focus();
    return false;
    }

    ...etc


    *** Common Functions

    // Strip spaces from input box.
    function stripSpaces(elm) {
    var x = elm.value;
    elm.value = (x.replace(/^\W+/,'')).replace(/\W+$/,'');
    }

    // Check for null and empty fields.
    function isFilled(elm) {
    if (elm.value == "" ||
    elm.value == null)
    return false;
    else return true;
    }

    Any suggestions?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    maxLen = 500; // max number of characters allowed in the textbox
    function checkMaxInput(form) {
    if (form.Description.value.length > maxLen) // if too long.... trim it!
    form.Description.value = form.Description.value.substring(0, maxLen);
    }

    The HTML is something like:-

    <textarea name=Description cols="60" rows="4" wrap=virtual onKeyDown="checkMaxInput(this.form)" onKeyUp="checkMaxInput(this.form)" ></textarea>

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Pretty much anything that works for an input type="text" should work for a textarea as well. A textarea is basically a multi-line input. What's this?

    enquiry.subject

    If it's part of a validator, it probably should be

    document.enquiry.subject

    Hard to say without seeing your HTML.
    Last edited by adios; 12-18-2003 at 07:04 PM.


  •  

    Posting Permissions

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