pls help me run this code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manu Ashok

    pls help me run this code

    can any body help me with this...........
    i donno what's happening.....t he value enterd is not being
    trimmed.....it leaves the blank spaces as it is in the form.


    <SCRIPT language=javasc ript>

    function trim(inputStrin g) {
    if (typeof inputString != "string") {
    return inputString;
    }
    var retValue = inputString;
    var ch = retValue.substr ing(0, 1);
    while (ch == " ") {
    retValue = retValue.substr ing(1, retValue.length );
    ch = retValue.substr ing(0, 1);
    }
    ch = retValue.substr ing(retValue.le ngth-1, retValue.length );
    while (ch == " ") {
    retValue = retValue.substr ing(0, retValue.length-1);
    ch = retValue.substr ing(retValue.le ngth-1, retValue.length );
    }
    while (retValue.index Of(" ") != -1) {
    retValue = retValue.substr ing(0, retValue.indexO f(" ")) +
    retValue.substr ing(retValue.in dexOf(" ") + 1, retValue.length );
    }
    return retValue;
    }

    function checkint(txtObj ) {
    var retValue;
    trim(txtObj);
    var numbervalue = txtObj;
    for(var i = 0; i < numbervalue.len gth; ++i){
    tmptegn = numbervalue.cha rAt(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="CategoryN ame" value="<%= CategoryName %>"
    maxlength=250 onBlur="trim(th is)"> </td>

    <td><input type=text name="CategoryC ode" value="<%= CategoryCode %>"
    maxlength=50 OnBlur="checkin t(this)"> </td>
  • Brian Genisio

    #2
    Re: pls help me run this code

    Manu Ashok wrote:
    [color=blue]
    > can any body help me with this...........
    > i donno what's happening.....t he value enterd is not being
    > trimmed.....it leaves the blank spaces as it is in the form.
    >
    >
    > <SCRIPT language=javasc ript>
    >
    > function trim(inputStrin g) {
    > if (typeof inputString != "string") {
    > return inputString;
    > }
    > var retValue = inputString;
    > var ch = retValue.substr ing(0, 1);
    > while (ch == " ") {
    > retValue = retValue.substr ing(1, retValue.length );
    > ch = retValue.substr ing(0, 1);
    > }
    > ch = retValue.substr ing(retValue.le ngth-1, retValue.length );
    > while (ch == " ") {
    > retValue = retValue.substr ing(0, retValue.length-1);
    > ch = retValue.substr ing(retValue.le ngth-1, retValue.length );
    > }
    > while (retValue.index Of(" ") != -1) {
    > retValue = retValue.substr ing(0, retValue.indexO f(" ")) +
    > retValue.substr ing(retValue.in dexOf(" ") + 1, retValue.length );
    > }
    > return retValue;
    > }
    >
    > function checkint(txtObj ) {
    > var retValue;
    > trim(txtObj);
    > var numbervalue = txtObj;
    > for(var i = 0; i < numbervalue.len gth; ++i){
    > tmptegn = numbervalue.cha rAt(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="CategoryN ame" value="<%= CategoryName %>"
    > maxlength=250 onBlur="trim(th is)"> </td>
    >
    > <td><input type=text name="CategoryC ode" value="<%= CategoryCode %>"
    > maxlength=50 OnBlur="checkin t(this)"> </td>[/color]

    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(trimRi ght(s)); }

    Brian

    Comment

    Working...