Jump to content

substr not giving result


mickeymouse
 Share

Recommended Posts

Trying to get the last character of a string but get absolutely nothing - no result, not even an alert execution.
What's wrong with my substr?  It seems to me it agrees with the W3S documentation.

function mychk(myfld)
{with (myfld)
{if(bud.checked==true)
    {var x = myfld.value;
    alert(x);  <--------------------------- Shows correct results
    var r = substr(myfld.value,-0,1);  <---------Trying to get thelast character of the string.
    alert(r);  <------------------------------ No alert at all
    }
}}
    NOT ANYBETTER IF I USE  
    	var r = substr(x,-0,1);
    	alert(r);  <-------------Still no alert.
                                               
                                               

 

Link to comment
Share on other sites

Thanks.  But what is the problem now?I keep getting the alert message no matter if my slice is a,l or any thing else.

function mychk(myfld)
{with (myfld)
{if(bud.checked==true)
    {var str = myfld.value;
    if(str.slice(-1) == 'a' || str.slice(-1) == 'l');
        {alert('TRANSACTIONS ARE NOT POSSIBLE FOR a OR l ACCOUNTS.');}  <------- I keep getting the message no matter what.
    }
}}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...