You need to sign in to do that
Don't have an account?
Subham
Make a button click on pressing enter button
Hey guys,
There is a scenario where there is a Input text file where i put any string for search
<td id="inputFilterBox" ><apex:inputText value="{!HIII}" id="inputtext" onclick="clearinputtext(this);"/></td>
And then i click on Search button and it returns me the result. but the requirement is that if user presses enter , Search button should be clicked or importantly Result should be displayed.
<input type="button" id="searchButton" value="Search" onClick="search(); return false;" />
try this. credits to sandersen
<apex:form id="searchForm">
<script type="text/javascript">
function noenter(e){
if(window.event){
key = window.event.keyCode; //IE
} else{
key = e.which; //firefox
}
if(key == 13) {
var ele=document.getElementById('contactMergePage:searchForm:searchButton');
ele.click();
return false;
} else{
return true;
}
}
</script>
<apex:inputText value="{!searchText}" id="searchText" onkeypress="return noenter(event);"/>
<apex:commandButton id="searchButton" action="{!search}" rerender="searchresults,selectedContacts,winnerpanel" value="Search" status="searchStatus"/>
<apex:actionStatus startText="(searching...)" id="searchStatus"/>
</apex:form>
All Answers
try this. credits to sandersen
<apex:form id="searchForm">
<script type="text/javascript">
function noenter(e){
if(window.event){
key = window.event.keyCode; //IE
} else{
key = e.which; //firefox
}
if(key == 13) {
var ele=document.getElementById('contactMergePage:searchForm:searchButton');
ele.click();
return false;
} else{
return true;
}
}
</script>
<apex:inputText value="{!searchText}" id="searchText" onkeypress="return noenter(event);"/>
<apex:commandButton id="searchButton" action="{!search}" rerender="searchresults,selectedContacts,winnerpanel" value="Search" status="searchStatus"/>
<apex:actionStatus startText="(searching...)" id="searchStatus"/>
</apex:form>
Thanks for teaching me how to do this:!!!!
How are you able to avoid the embedded id information provided by salesforce. You know, the somewhat random "...j_id153:MyRealId"?
Hi,
I have a similar requirement.
i have 3 buttons, previous, reset and submit and i need to make submit button my default button i.e., on click of enter submit should be clicked.
when i tried your code, it didnt click the submit button instead Previous is getting clicked (Previous is the frist button so i assume that is why it is getting clicked).
will it matter if we have multiple button on the page?
also at what level should should we call the javascript?
Are you sure that the document.getElementById that you call in the javascript is the id of the submit button?
yes..
<
b/>
<apex:commandButtonid="submit"value="Submit"action="{!addDetails}"onClick="return alert1();"/>
Also, getelement by id is returning null.
var ele=document.getElementById('submit');
alert(ele);
Please let me know if i m doing anything wrong.
button was not getting clicked as I was trying on firefox.
To click a button on firefox use the soln in the below link:
http://developer.force.com/cookbook/recipe/submit-a-form-with-the-enter-key