[SalesForce] ActionFunction working in Chrome but not in IE and Moz

So, the page has an action which must be invoked when "enter" is pressed.

VISUALFORCE:

//script:
function pressReturn(e, currOffer) {
    var keyPressed = e.keyCode;
    if (keyPressed == 13) {    
        insertOffer(currOffer);        
    }
}

//Action Function:
<apex:actionFunction name="insertOffer" action="{!setNewBidOffer}">
     <apex:param name="currOffer" value="currOffer" assignTo="{!currentOffer}"/>
</apex:actionFunction>

//input fiel:
<apex:inputText value="{!currentOffer}" onkeypress="return pressReturn(event, j$(this).val());"/>

The action invoked by the controller (setNewBidOffer) does stuff and then returns a PageReference null.

In chrome everything works fine: the user writes, presses enter, the javascript is called, setNewBidOffer is done, null is returned and the page is refreshed.

This is not happening in mozilla and in IE. I tried to set some debug logs in the action setNewBidOffer and apparently, when I use mozilla or IE, the action in the controller is not even called.

What am I missing? thank you very much for your patience and attention!

Best Answer

Try to use jQuery to trigger on the keyPress/keyDown events. Additionally i leave the value parameter empty if i want to set it from another javascript function and use reRender to refresh some areas:

<script>
jQuery('[id$=myField]').on('keydown keypress keyup', function(event) {
    if (event.keyCode == 13) {
        event.preventDefault();
        insertOffer(jQuery(this).val());
    }
});
</script>


<apex:actionFunction name="insertOffer" action="{!setNewBidOffer}" reRender="myField">
     <apex:param name="currOffer" value="" assignTo="{!currentOffer}"/>
</apex:actionFunction>

<apex:inputText value="{!currentOffer}" id="myField"/>

But one thing i don't understand: you trying to set the currentOffer variable to the currentOffer variable?