1

The following homepage component passes the value from an HTML input to a URL, using the value as the filter criteria for 3 separate parameter values. Everything works fine, except it doesn't submit when I hit enter! I have to manually click the button. Anyone have any idea how to make the jscript function run on Enter as well as onclick. P.S. I've already tried replacing onclick with onsubmit - no dice. It just refreshes the page rather than redirecting to the intended URL.

<script type="text/javascript"> 
function accountSearch() { 
var userInput = document.getElementById('pv0').value; 
window.location.href ='/00Oe0000000FRlj?pv0='+userInput+'&pv1='+userInput+'&pv2='+userInput; 
}
</script>
<form onsubmit="accountSearch();">
Account Name:<input type="text" name="pv0" id="pv0"> <br>
<input type="button" onclick="accountSearch();" value="Submit">
</form>
0

You need to be capturing the actual press of enter, not the submission of the form. The below link describes how to do so:

https://stackoverflow.com/questions/764427/how-to-capture-enter-key-being-pressed-on-pages-containing-multiple-forms

0

Just fyi, here's the solution to the above question:

<script type="text/javascript">
function accountSearch() {
var userInput = document.getElementById('pv0').value;window.location.href = '/00Oa0000008Fz9w?pv0='+userInput+'&pv1='+userInput+'&pv2='+userInput;  
return false;
}
</script>
<form>Account Name:<input type="text" name="pv0" id="pv0" autocomplete="off" onkeypress="javascript:if (event.keyCode==13);
return accountSearch();"><br>
<input type="button" onclick="accountSearch();" value="Submit">
</form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.