469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

pls help me run this code

can any body help me with this...........
i donno what's happening.....the value enterd is not being
trimmed.....it leaves the blank spaces as it is in the form.
<SCRIPT language=javascript>

function trim(inputString) {
if (typeof inputString != "string") {
return inputString;
}
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") {
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") {
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) {
retValue = retValue.substring(0, retValue.indexOf(" ")) +
retValue.substring(retValue.indexOf(" ") + 1, retValue.length);
}
return retValue;
}

function checkint(txtObj) {
var retValue;
trim(txtObj);
var numbervalue = txtObj;
for(var i = 0; i < numbervalue.length; ++i){
tmptegn = numbervalue.charAt(i);
if (tmptegn < "0" || tmptegn > "9"){
if(tmptegn == " ")
i++;
else
{ alert("only numeric value accepted")
txtObj.focus();
txtObj.select();
return;
}
}
return true;
}
}

in the form i call it as follows

<td><input type=text name="CategoryName" value="<%= CategoryName %>"
maxlength=250 onBlur="trim(this)"> </td>

<td><input type=text name="CategoryCode" value="<%= CategoryCode %>"
maxlength=50 OnBlur="checkint(this)"> </td>
Jul 23 '05 #1
1 1186
Manu Ashok wrote:
can any body help me with this...........
i donno what's happening.....the value enterd is not being
trimmed.....it leaves the blank spaces as it is in the form.
<SCRIPT language=javascript>

function trim(inputString) {
if (typeof inputString != "string") {
return inputString;
}
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") {
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") {
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) {
retValue = retValue.substring(0, retValue.indexOf(" ")) +
retValue.substring(retValue.indexOf(" ") + 1, retValue.length);
}
return retValue;
}

function checkint(txtObj) {
var retValue;
trim(txtObj);
var numbervalue = txtObj;
for(var i = 0; i < numbervalue.length; ++i){
tmptegn = numbervalue.charAt(i);
if (tmptegn < "0" || tmptegn > "9"){
if(tmptegn == " ")
i++;
else
{ alert("only numeric value accepted")
txtObj.focus();
txtObj.select();
return;
}
}
return true;
}
}

in the form i call it as follows

<td><input type=text name="CategoryName" value="<%= CategoryName %>"
maxlength=250 onBlur="trim(this)"> </td>

<td><input type=text name="CategoryCode" value="<%= CategoryCode %>"
maxlength=50 OnBlur="checkint(this)"> </td>


Way too complicated... Try this... It will trim tabs and spaces from
both ends.

function trimLeft(s) { return s.replace(/^[\t ]+/, ""); }
function trimRight(s) { return s.replace(/[\t ]+$/, ""); }
function trim(s) { return trimLeft(trimRight(s)); }

Brian

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

51 posts views Thread by Mudge | last post: by
9 posts views Thread by bigoxygen | last post: by
4 posts views Thread by jason | last post: by
16 posts views Thread by Dario de Judicibus | last post: by
109 posts views Thread by Andrew Thompson | last post: by
18 posts views Thread by Joe Fallon | last post: by
171 posts views Thread by tshad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.