Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8827805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:27:35+00:00 2026-06-14T07:27:35+00:00

I have some code that I have managed to get working in Chrome, IE8,

  • 0

I have some code that I have managed to get working in Chrome, IE8, but not FireFox. BTW: my a4j: namespace is a:

The idea is simple, you want to be notified when item is out of stock so you enter your email and we replace the tiny form with a simple Thank you div.

In FireFox however It correctly sumbits to the database though the action and it’s bean method. Then oncomplete it fires a JS function and does show the thank you message, but then the page completes its reload I think and the original form reappears which we do not want!

First the RichFaces and Events in the front page codel

<h:inputText id="email" value="#{customer.stockWatch.email}"
    converter="TextTrimConverter"
    onfocus="if(this.value == 'Enter email address'){ this.value=''; }"
    onblur="if(this.value.trim() == ''){ this.value='Enter email address'; }"
    onkeypress="stockWatchEnterSubmit(event.keyCode);" />

<a:commandLink styleClass="b_submit" id="stockwatchSubmit"
    action="#{customer.stockWatch}"
    oncomplete="stockWatchTextChange(); return false;">
    <span>#{messages.submit}</span>
</a:commandLink>

And now the 2 simple javascript functions I use:

function stockWatchTextChange() {
    document.getElementById('fstockwatch').setAttribute('id', 'fstockwatch_thanks');
    document.getElementById('fstockwatch_thanks').innerHTML = 'Thank you. We\'ll send you an email once this item is back in stock';
}

function stockWatchEnterSubmit(keyCode) {
    if(keyCode == 13){
        document.getElementById('stockwatchSubmit').click();
    }
}

Thanks for your help. Got it working in 2 out of 3 browsers! But not good enough!! 😉

The JSF is version 1.2 and RichFaces is I think 3.01? I found the exact version of RichFaces:
The version is richfaces-api-3.3.1.GA.jar

Edit:
I wish there was more information I could provide. This may be in fact a case of ajax4jsf / a4j simply failing when there are multiple separate pieces of a4j logic on the web page… but the thing is, they are obviously all not being used at the same time. So something LIKE what I have done should work yes? Some changes to the code next:

<h:form id="detailForm" prependId="false">
<h:inputText id="email" value="#{customer.stockWatch.email}"
    converter="TextTrimConverter"
    onfocus="if(this.value == 'Enter email address'){ this.value=''; }"
    onblur="if(this.value == ''){ this.value='Enter email address'; }"
    onkeypress="if(event.keyCode == 13){document.getElementById('stockwatchSubmit').click(); if(event.preventDefault){event.preventDefault();}else{event.returnValue = false;}}" />

<a:commandLink styleClass="b_submit" id="stockwatchSubmit"
    action="#{customer.stockWatch}"
    oncomplete="stockWatchTextChange();">
    <span>#{messages.submit}</span>
</a:commandLink>
</h:form>

I only use one JavaScript function now as well, and that is to change the id value of the wrapper div (because it will change the css) and then to update the innerHTML.

One more piece of information that may be helpful in solving this is that many many times as I rewrote and rewrote the JSF/RICHFACES to get it to work –> in all browsers by pressing ENTER Key AND Clicking a Submit button..

I would see the action attribute simply NOT firing the method in the bean. I have a sysout as soon as you enter the method so I can see it in my console. And this is not happening. Our system is pretty robust so I am not sure what to think. Except that a4j is broken? at least in the version we are running.. I mean this is pretty simple code and the action attribute is not making it to the method! =)

I mean to say, it does work sometimes, various itterations as I am trying to get it to work on ALL browsers the method does fire and a record is inserted into a DB.

But other revisions of the code the action attribute simply does not fire. That is what I am trying to say.

Thanks again all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:27:36+00:00Added an answer on June 14, 2026 at 7:27 am

    Your concrete problem is caused by a double submit on enter key.

    In the input field you have an onkeypress handler which triggers the click event on the submit button when the enter key is pressed. But you aren’t preventing the event’s default behaviour (as would have been exposed when there’s no onkeypress handler). In Firefox, apparently, submitting the ajax form with a command link works via pressing enter.

    You basically need to prevent the event’s default behaviour. The easiest crossbrowser way to achieve this is returning false from the onkeypress handler.

    onkeypress="if (event.keyCode == 13) { document.getElementById('stockwatchSubmit').click(); return false; }"
    

    If you’d like to refactor it into a function, let it return a boolean.

    onkeypress="return stockWatchEnterSubmit(event.keyCode)"
    

    with

    function stockWatchEnterSubmit(keyCode) {
        if (keyCode == 13) {
            document.getElementById('stockwatchSubmit').click();
            return false;
        } else {
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far I have managed to write some code that should print the source
Possible Duplicate: Browser Independence issue Code Working for IE but not for Firefox and
I have some code that will change the background color of a specific label
I have some code that is supposed to return an NSString. Instead it is
I have some code that generates Visio masters for me, and some masters have
I have some code that causes the box2d physics simulation to stutter forever after
I have some code that runs a model in a loop. Each iteration of
I have some code that shows results in a table Right now it will
I have some code that uses the SQL Server 2005 SMO objects to backup
I have some code that looks like this: foreach(var obj in collection) { try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.