Jump to content
mickeymouse

substr not giving result

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.
                                               
                                               

 

Share this post


Link to post
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.
    }
}}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...