Forum Moderators: open
Use the string object and the substring method. First number is where it starts, remember javascript starts at 0, and the second number is where it starts but does not include that character.
here is a example page that may help:
<html>
<head>
<title>Untitled</title>
<script>
function trimS(){
var text1=document.form1.textbox1.value;
var showMe = text1.substring(1, 4);
document.form1.textbox2.value=showMe;
}
</script>
</head>
<body>
<form name="form1" onSubmit="trimS(); return false">
<input type="text" name="textbox1">
<input type="submit">
<input type="text" name="textbox2">
</form>
</body>
</html>
Substring can be used to get from a start char to the end of the string also, by just passing it the start char, i.e.,
string.substring(4); will get from char 4 to string.length. The other thing I use it for alot is to snip out or replace known sections of an unparsed string, i.e.,
var a = string.substring(0, string.indexOf("example")); var b = string.substring(string.indexOf("example") + "example".length); string = a + "this used to say 'example'" + b; Jordan