473,380 Members | 1,230 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,380 software developers and data experts.

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 13057
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

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

Similar topics

1
by: fogwolf | last post by:
First a basic outline of what I am trying to do: I want to have a page spawn a pop-up when you click "submit" on its form. On this pop-up page there will be another form. When you click "submit"...
1
by: chad.arimura | last post by:
I've got a form inside a PHP script that posts to itself, does some processing on the PHP side, and if it looks good, PHP sends a HEADER command that redirects the user out. All was fine until I...
24
by: bedhead | last post by:
Why doesn't a SELECT element's innerHTML reflected which option was selected? Works in IE. I need this functionality so that I can retain what choices a user made in a tabbed interface. ...
4
by: Nacho Nachev | last post by:
This may sound like a silly question, but what is the appropriate way to handle form double submitting in ASP.NET. Page expiration, etc? I am looking for a way to handle this in some cetral point...
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
5
by: Andrea | last post by:
I am trying to alter css using javascript as well as use the innerHTML function. I have pasted below 3 forms that access getElementById in slightly different ways (I wanted to rule out that it was...
1
by: gferreri | last post by:
Hi all, I've stumbled on an interesting problem with the way Firefox handles form submitting with the enter key. I'm putting together a page that has one form element with multiple controls...
7
by: mohammed.naghman | last post by:
Hi, I have 2 submit buttons in a jsp page. One of them takes me to page2.jsp and also passes the values enetered to page2.I have a link in the page2 that does a history.back to come to the...
9
by: Ned White | last post by:
Hi All, Im my c# web project, users click a submit button for credit card payment process. On the web server side ( on ButtonClick_Event) the user's input(name,date,cc number etc.) is processed...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.