I am trying to create a code that will fill in "name" based on the search portion (?John-Doe) of a url. However, if there is no search portion, i would like it to default to the pathname.
For instance test.com/contact?John-Doe
or parse from the following if the search is not present
test.com/John-Doe
<script type="text/javascript">
window.onload=function() {
document.getElementById('name').value = window.location.pathname.substr(1).replace(/-/g, " ");
}
</script>
thanks for any help you can provide!