mickeymouse 0 Posted February 22, 2020 Report 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. Quote Link to post Share on other sites
dsonesuk 929 Posted February 22, 2020 Report Share Posted February 22, 2020 You are mixing javascript code with php? When you decide on the one you want, repost. Quote Link to post Share on other sites
mickeymouse 0 Posted February 22, 2020 Author Report 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. } }} Quote Link to post Share on other sites
dsonesuk 929 Posted February 22, 2020 Report Share Posted February 22, 2020 Remove semi colon from if condition. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.