...

View Full Version : Trim text in TEXTAREA



tisdale
12-18-2003, 04:04 PM
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?

Philip M
12-18-2003, 07:50 PM
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>

adios
12-18-2003, 07:59 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum