I have several identical HTML files that all have different names:
3089.html
68985.html
101.html
...and more
Each file has an input field with an id of "productsku":
<input type='text' id='productsku' />
I would like this field to be filled with the name of the HTML file. I only want to use Javascript to do this (I don't want to use jQuery, as I don't want to load the jQuery library for such a small task).
Here is my Javascript code:
<script>
window.onload = function(){
document.getElementById('productsku').value=location.pathname;
}
</script>
It works, but it puts the file name extension and path rather than just the name.
e.g. it puts /path/3089.html
rather than just "3089"
Is there any way I can correct this?
Here is a JS fiddle.