pls help me run this code

M

Manu Ashok

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>
 
B

Brian Genisio

Manu said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top