mickeymouse Posted February 22, 2020 Share Posted February 22, 2020 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 More sharing options...
dsonesuk Posted February 22, 2020 Share Posted February 22, 2020 You are mixing javascript code with php? When you decide on the one you want, repost. Link to comment Share on other sites More sharing options...
mickeymouse Posted February 22, 2020 Author Share Posted February 22, 2020 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 More sharing options...
dsonesuk Posted February 22, 2020 Share Posted February 22, 2020 Remove semi colon from if condition. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now