469,271 Members | 1,176 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

FireFox submitting form twice

3
I have a couple of forms that are misbehaving in FireFox, but work fine in IE.

when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the submission if there is an error.

Sample (obviously not working code):
[HTML] <html>
<head>
<script type="text/javascript">
function Submit()
{
// do something, like form field validation before submitting
return true;
} else {
return false; // do nothing, do not submit the form
}
}
</script>
</head>
<body>
<form name="myForm" action="form.cgi" onSubmit="return Submit()>
Some form fields here<br/>
<input type="submit" value="Submit" >
</form>
</body>
</html>
[/HTML]



THE PROBLEM:
In IE, the script performs as expected.

In FireFox (tested in v2.0.0.3):
* if the form validates correctly, it gets submitted twice:
* if the form doesn't validate then nothing happen.

Am I coding something wrong here? Why is FireFox submitting the form two times..
Apr 24 '07 #1
18 12251
r035198x
13,262 8TB
I have a couple of forms that are misbehaving in FireFox, but work fine in IE.

when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the submission if there is an error.

Sample (obviously not working code):
<html>
<head>
<script type="text/javascript">
function Submit()
{
// do something, like form field validation before submitting
return true;
} else {
return false; // do nothing, do not submit the form
}
}
</script>
</head>
<body>
<form name="myForm" action="form.cgi" onSubmit="return Submit()>
Some form fields here<br/>
<input type="submit" value="Submit" >
</form>
</body>
</html>



THE PROBLEM:
In IE, the script performs as expected.

In FireFox (tested in v2.0.0.3):
* if the form validates correctly, it gets submitted twice:
* if the form doesn't validate then nothing happen.

Am I coding something wrong here? Why is FireFox submitting the form two times..
I'm not a FireFox guru and am just trying my luck here,
What happens if you call the function onClick of the submit button rather than onSubmit of the form?
Apr 24 '07 #2
try to change the function name
Apr 24 '07 #3
r035198x
13,262 8TB
try to change the function name
Of course. That should be it.
Apr 24 '07 #4
NavinM
3
i tried to use onclick and the results are same.
btw, onclick event will take care of only mouse click.
but i need to make it generic,
I want to use all three cases.
a) submitting page by enter.
b) submitting page by click
c) submitting page by space when control is on submit button,

i have tried with changing function but no luck.

is there any other way, i can look on.

Thanks
Apr 25 '07 #5
r035198x
13,262 8TB
i tried to use onclick and the results are same.
btw, onclick event will take care of only mouse click.
but i need to make it generic,
I want to use all three cases.
a) submitting page by enter.
b) submitting page by click
c) submitting page by space when control is on submit button,

i have tried with changing function but no luck.

is there any other way, i can look on.

Thanks
Can you post the code you have now with the function name changed
Apr 25 '07 #6
Grimm
4
Firefox automaticqally follows the submit standard function after an event has occured when using a submit button...if you change the button type to button instead of submit and change the function name it will work normally. Unfortunatley you loose some of the other funtionality options you want but give a little to get a little. Sorry
Apr 25 '07 #7
NavinM
3
Firefox automaticqally follows the submit standard function after an event has occured when using a submit button...if you change the button type to button instead of submit and change the function name it will work normally. Unfortunatley you loose some of the other funtionality options you want but give a little to get a little. Sorry

i found the solution afterall :)
the page was being loaded with GET method and issue was -- " mismatching of character encoding" ( hence GET was being executed Twice )
i used Central European ISO-8859-2 and everything is working fine

refer the below link for more details ..
http://forums.mozillazine.org/viewto...859258#2859258

Regards
Navin
Apr 26 '07 #8
I'm still getting the problem. I've checked and set the charset encoding on the response header but with no luck [UTF-8]. FF still issues a Post and then a Get. Could someone please detail out how the solution is working for them.

One thing to note is that I use javascript to submit my form onchange of a text field. That should not make a difference.

The page meta tags -
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Pragma" content="nocache"/>
<meta http-equiv="Cache-Control" content="private"/>
<meta http-equiv="Cache-Control" content="proxy-revalidate"/>

Note I tried with the following as well -
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Pragma" content="no-cache,no-store,max-age=0"/>
<meta http-equiv="Cache-Control" content="nocache"/>

In my servlet I set the following

response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
response.setHeader("Content-Type", "text/html; charset=UTF-8");
response.setDateHeader("Expires", 1);


Am I doing something wrong here?
May 9 '07 #9
acoder
16,027 Expert Mod 8TB
I'm still getting the problem. I've checked and set the charset encoding on the response header but with no luck [UTF-8]. FF still issues a Post and then a Get. Could someone please detail out how the solution is working for them.

One thing to note is that I use javascript to submit my form onchange of a text field. That should not make a difference.

The page meta tags -
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Pragma" content="nocache"/>
<meta http-equiv="Cache-Control" content="private"/>
<meta http-equiv="Cache-Control" content="proxy-revalidate"/>

Note I tried with the following as well -
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Pragma" content="no-cache,no-store,max-age=0"/>
<meta http-equiv="Cache-Control" content="nocache"/>

In my servlet I set the following

response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
response.setHeader("Content-Type", "text/html; charset=UTF-8");
response.setDateHeader("Expires", 1);


Am I doing something wrong here?
What's the character encoding in your browser?
May 9 '07 #10
What's the character encoding in your browser?
The browser encoding is - UTF-8
I've narrowed it down to my javascript stmt.
Expand|Select|Wrap|Line Numbers
  1. function mysubmit(){
  2. alert('1');
  3. document.forms[0].submit();
  4. alert('2');
  5. }
  6.  
alert('1') is displayed - No request yet submitted, Press OK, alert 2 is displayed. 2 requests submitted.
May 9 '07 #11
pbmods
5,821 Expert 4TB
Change the action of your form:

[HTML]
<form ... action="mySubmit();">
[/HTML]

And then instead of returning true in mySubmit:

Expand|Select|Wrap|Line Numbers
  1. document.forms[0].action = 'thepage.php';
  2. document.forms[0].submit();
  3.  
May 10 '07 #12
I tried to make the form action="" and set the action explicitly in the js, returned true from it. Still doesn't work.
My requirement is that the js should be called onchange of a text field, hence I've made the form action as an empty string
May 10 '07 #13
pbmods
5,821 Expert 4TB
I tried to make the form action="" and set the action explicitly in the js, returned true from it. Still doesn't work.
My requirement is that the js should be called onchange of a text field, hence I've made the form action as an empty string
If the form's action is an empty string, then it will use the current page as the action. Instead, do this:

Expand|Select|Wrap|Line Numbers
  1. form.action = 'void('');';
  2.  
May 10 '07 #14
If the form's action is an empty string, then it will use the current page as the action. Instead, do this:

Expand|Select|Wrap|Line Numbers
  1. form.action = 'void('');';
  2.  

That doesn't help either
May 10 '07 #15
pbmods
5,821 Expert 4TB
That doesn't help either
What's not working about it?

I'm not sure I understand how the code is fitting together; perhaps if you posted the current implementation.
May 10 '07 #16
What's not working about it?

I'm not sure I understand how the code is fitting together; perhaps if you posted the current implementation.
Here's a cut down version of my page. I've got firebug running and it issues a new get request as soon as the page is done 'rendering' the last function in the script tag below.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3.  <head>
  4.   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5.   <meta http-equiv="Pragma" content="nocache"/>
  6.   <meta http-equiv="Cache-Control" content="private"/>
  7.   <meta http-equiv="Cache-Control" content="proxy-revalidate"/>
  8.  
  9.  
  10.  </head>
  11.  <body class="body" style="overflow:auto">
  12.   <form method="post" action="http://localhost:7001/mypage.jsp" id="S_25403" name="S_25403">
  13.    <input type="text" id="TransactionCode" title="Transaction Code" onchange="mydispatch('TransactionCode');" name="TransactionCode" value=""/>
  14.   </form>
  15.   <!-- Javascript -->
  16.   <script type="text/javascript" language="javascript1.1"><!--
  17. var pageRefreshed = true;
  18.  
  19. function mydispatch(id, cmd) {
  20.   if (pageRefreshed) {
  21.     pageRefreshed = false;
  22.     document.forms[0].submit();
  23.   }
  24.   return true;
  25. }
  26.  
  27. --></script>
  28.  </body>
  29.  
  30. </html>
  31.  

The headers for the 1st POST
Cache-Control private,proxy-revalidate, private, proxy-revalidate
Date Thu, 10 May 2007 03:00:02 GMT
Pragma No-cache, nocache
Transfer-Encoding chunked
Content-Type text/html; charset=UTF-8
Expires Thu, 01 Jan 1970 00:00:00 GMT
X-Powered-By Servlet/2.4 JSP/2.0
robots NOINDEX,NOFOLLOW
Request Headers
Host localhost:7001
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive

And the second GET
Connection close
Date Thu, 10 May 2007 03:00:04 GMT
Content-Length 2234
Content-Type text/html
X-Powered-By Servlet/2.4 JSP/2.0
Request Headers
Host localhost:7001
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Accept image/png,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
May 10 '07 #17
Solved the problem, just wanted to update the post with what he problem was-
One of my open-source js files was putting <img src="".... which was causing the page url to be accessed again.
Changed it access a null image, and it worked.

Please note that all other changes - Setting of response headers, changing the focrm action etc. were reverted back, and it still worked.

Thanx for all your help
May 10 '07 #18
acoder
16,027 Expert Mod 8TB
Solved the problem, just wanted to update the post with what he problem was-
One of my open-source js files was putting <img src="".... which was causing the page url to be accessed again.
Changed it access a null image, and it worked.

Please note that all other changes - Setting of response headers, changing the focrm action etc. were reverted back, and it still worked.

Thanx for all your help
Glad you got it working. It can be so frustrating when you realise you'd been barking up the wrong tree.
May 11 '07 #19

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by fogwolf | last post: by
1 post views Thread by chad.arimura | last post: by
24 posts views Thread by bedhead | last post: by
4 posts views Thread by Nacho Nachev | last post: by
6 posts views Thread by Mark Olbert | last post: by
5 posts views Thread by Andrea | last post: by
7 posts views Thread by mohammed.naghman | last post: by
9 posts views Thread by Ned White | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.