Does JavaScript have any functions like VB's left function and len function for strings? I want to change the last character on a comma-delimited string and I need something to do this.
you can do mostly everything VB can do in JS (as far as web pages are concerned).
to check the length of a string you can do :
var myString = "this is my test string"
alert(myString.length)
Also if you have a string like this one "test,test,test,test" you can change it to an array using split(',') and remove the last element in it.
var myString = "test,test,test,test";
alert("my original string " + myString)
var myArray = myString.split(',')
myArray.pop(); // removes the last element of my array
myString = myArray.join(','); // creates a coma delimited string
alert("now my string with the last element removed " + myString)
What I really want to do is change the value of a checkbox on a form. Right now I have a value on the checkbox that is a string of comma-delimeted parameters. I use these to build a query string to pass to a popup window that runs some asp code and returns values back to the parent page in javascript. I want to change the last character on the checkbox value from the child page so I need to run something like in vb:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.