I'm trying to take a {variable} string and cut it down for entry into a search box (input field). Here's an example of where I've got to by combining a couple of things I've found, but I only know the very basics of JS apart from some applications.
<script type="text/javascript">
var str="SL-NL-CC0020301";
document.getElementById("txtSearch").write(str.slice(6));
</script>
I know this doesn't work, but is there a proper way to slice a string then enter it into a field using something similar to getElementById?
(Note that "SL-NL-CC0020301" 开发者_开发问答is an example of text that is generated by a {variable} tag that usually sits in that spot)
If you're trying to write it as the value of an INPUT element, use:
<script type="text/javascript">
var str="SL-NL-CC0020301";
document.getElementById("txtSearch").value = str.slice(6);
</script>
精彩评论