I have this script that is changing the value of an input field.
The output I want is like: A-Z. (A. and B. end so on)
How can I achieve that everything after the “.” is being stripped.
<script language="JavaScript">
function hoofdlettermetpunt(obj)
{
var firstChar = document.all(obj).value.charAt(0);
firstChar = firstChar.toUpperCase() + ".";
document.all(obj).value = document.all(obj).value.replace(
document.all(obj).value.charAt(0), firstChar);
}
</script>
To strip anything away after a dot
.from a string you can use the following:I’m not sure what you are trying to do with your code to actually answer your question in terms of your example however. Basically
.splitwill always return an array so you can use[0]as an array access straight afterwards – which will give you the first found element in the array (which because of the split, will be the substring you want). The above will work even if the string doesn’t contain a..For information about
.split()see below:http://www.w3schools.com/jsref/jsref_split.asp