Reputation: 636
In my javascript file, I have a code snippet like:
$('<form action="process.php" method="POST">' +
'<input type="hidden" name="amp" value="' + calcJSON.totalAmpDay + '">' +
'<input type="hidden" name="watt" value="' + calcJSON.maxWattRate + '">' +
'<input type="hidden" name="dc_volt" value="' + document.number.dc_volt.value + '">' +
'</form>').submit();
The above code is included within a function definition. When I click a button, that function is called and then the browser should be redirected to "process.php" page with some POST data. But only Chrome redirects me to a new page but Firefox wont.
How can this issue be resolved ?
Upvotes: 2
Views: 1461
Reputation: 824
Just as a suggestion for good, debug it with firebug to see the error and append it to discussion to see what is actually happening.That helps to pinpoint the problem and help. See:firebug breakpoint
Upvotes: 0
Reputation: 56
Had this same problem about a week ago. I stand to be corrected but I believe in Firefox the form has to be added to the DOM before it can be submitted. I solved this by setting the CSS to "display: none" and added the form to an arbitrary element on the page before running the submit method.
Upvotes: 3
Reputation: 24226
Alert (or console.log) the -
var formtext ='<form action="process.php" method="POST">' +
'<input type="hidden" name="amp" value="' + calcJSON.totalAmpDay + '">' +
'<input type="hidden" name="watt" value="' + calcJSON.maxWattRate + '">' +
'<input type="hidden" name="dc_volt" value="' + document.number.dc_volt.value + '">' +
'</form>'
alert(formtext);
string before submitting the form. Does the string look like a valid form definition?
Upvotes: 1