Firefox submits form twice... why?
Hi All,
I'm getting some really weird behaviour from Firefox (7.0.1).
I writing a little blackjack training script in php. The script shuffles four decks of cards, then uses the shuffled shoe until it reaches the end, at which time it reshuffles.
Each card is then dealt from the shuffled deck in sequence, and used cards aren't recycled until the next shuffle.
The suffled sequence of cards and the current card number in the sequence are stored by php in $_SESSION variables.
So far, what I've written works fine in Chrome/Iron, Safari, IE and Opera, but an error in Firefox has me baffled.
This form creates a slection of next activities...
HTML Code: <form name='what' id='what' method='POST' action='blackjack.php' target='_self'> <input type='hidden' id='act' name='act' value=> <input type='hidden' id='draw' name='draw' value='".$draw."'> <input type='button' value='DRAW' onclick="set('draw')"> <input type='button' value='DOUBLE' onclick="set('double')"> <input type='button' value='SPLIT' onclick="set('split'); return false;"> <input type='button' value='STAND' onclick="set('stand'); return false;"> <input type='button' value='DEAL' onclick="set('deal'); return false;"> <input type='button' value='SHUFFLE' onclick="set('shuffle'); return false;"> </form>
And this little bit of javascript adjusts the value of 'act' and submits the form... HTML Code: <script type='text/javascript'> function set(w) { document.getElementById('act').value = w; document.getElementById('what').submit(); } </script>The php script will only shuffle the deck when act="shuffe" or act="".
However, in Firefox, the deck is shuffled on every submit.
I put some tracers in the php script and saw something weird. When firefox submits the form, it does so twice, once with the values of act and draw set, and the other with no values. What's returned to the browser is the result from the first submit (with the values set) except that by the time the php reaches the part of the code that retrieves the shoe, the second submit seems to have stored a new shuffled deck in the session variable.
You can try it, and see the source code and tracers here (though don't expect a functioning game)... BlackJackBlack
My brain hurts. Any thoughts?
CTB
All Replies (1)
A good place to ask advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.
The helpers at that forum are more knowledgeable about web development issues.
You need to register at the mozillaZine forum site in order to post at that forum.