I have a piece of code that I have been getting help on and I have come across something that I find inconvenient. When I click the "Go" button it browses away from the current tab. I want to have the resulting URL from the form to open in a new tab. in addition I cannot hit the enter key because it will just load the whole form up in a new window. How do I correct the "enter" key usage problem and get my form to open the URL in a new tab. The forms function is to open a new URL that contains information I am searching for. Here is my code:
<script type="text/javascript">
function setSearchTermSN(n){
var SN_VALUE = encodeURIComponent(document.getElementById("sn").value);
location.href = "http://URL to site.com/perl/search?searchtype=sn&type=2&uid=" + SN_VALUE + "&visualtype=html%2Fen&tabset=person";
}
</script>
<form target="_blank">
Last Name: <input id="sn" type="text" value="" />
<input type="button" value="Go" onclick="setSearchTermSN()" />
</form>
the idea is to enter a last name such as Jones into the input box. Click go and the form would substitute " + SN_VALUE + " with Jones and the load the URL like this:
http://URL to site.com/perl/search?searchtype=sn&type=2&uid=Jones&visualtype=html%2Fen&tabset=person
the form currently does the substitution but it browses away from the search box which defeats the purpose of having it. I have tried the <form target="_blank"> but it still opens the URL in the same page.
credit for the above code goes to https://stackoverflow.com/users/904428/david
<form onsubmit="return false;">