Issue with document.Form.submit not working in combination with window.location in Chrome and some versions of IE 7 and 8

Hey there, I'm currently working on a project that involves conducting surveys. Each page of the survey presents a new question for the user to answer, and upon submission, the user is redirected to the next question. The javascript code below allows this functionality.

function nextPage (nurl,findate,user_type) {

                if(((findate == null)||(findate=="0000-00-00"))&&((user_type != "survey owner"))&&(user_type !="PI admin")){

                    document.showQuestionAnswerForm.submit();
                    scode= document.getElementById('surveyCode').value;
                    parent.SurveySummaryFrame.location="load_survey.php?scode="+scode + "&template=" + '<? echo $_GET["template"]?>';

                }
                window.location.href=nurl;

            }

While this code is mostly reliable with Firefox and IE6, it occasionally encounters issues with IE7, IE8, and consistently fails with Google Chrome. Removing window.location.href=nurl; allows for successful submission, though leaving it uncommented leads to the user response not being saved before moving to the next url. My suspicion is that certain browsers process the code too quickly, potentially skipping the submission step. I'm in desperate need of a solution to rectify this issue. Any assistance would be greatly appreciated.

Answer №1

My recommendation would be to utilize ajax to submit the form and then redirect once the ajax form submission is complete.

One of the easiest ways to achieve this is by using jQuery's post function. However, it is important to have a good understanding of jQuery beforehand. http://api.jquery.com/jQuery.post/

Answer №2

Is there really a need to utilize Ajax when we already have the .submit method that can accomplish the task?

Nevertheless....

I encountered the same issue where everything worked perfectly in all browsers except for Google Chrome.

I attempted

document.NonJava.submit();
document.forms[0].submit();

as well as other methods.

Ultimately, this approach resolved the issue:

var frm = document.getElementById('NonJava');
frm.submit();

Voila!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I have written code in JavaScript, but now I am interested in converting it to jQuery

What is the best way to convert this to jQuery? showDish("balkandish1") function showDish(dishName) { var i; $(".city").css('display', 'none'); $("#" + dishName).css('display', 'block'); } ...

Navigating Angular on Internet ExplorerUnderstanding Angular's Compatibility

Having some trouble with an Angular app I'm developing. It displays perfectly on Chrome, but not at all on IE. Any tips on how to configure IE to show it correctly, or should I make changes to the app to ensure compatibility with IE? You can see how i ...

What causes the "This page isn't responding" error to pop up in Edge and Chrome browsers while attempting to perform consecutive tasks in a web application built with Angular 8?

Trouble with Page Loading Whenever this error occurs, I find myself unable to perform any activities on that page. The only solution is to close the tab and open a new one. My current code allows me to navigate through an array list (Next and Previous) us ...

What is the best method for obtaining the HTML content of a webpage from a different domain?

I'm in the process of creating a website where I have the requirement to retrieve the HTML content of a different site that is cross-domain. Upon researching, I came across YQL. However, I don't have much experience with YQl. Is it possible to ad ...

Stacking items when clicked on with jQuery UI Draggable

Can a draggable's stack procedure be activated by clicking instead of just dragging? I came across this solution, which essentially replicates the library code (with an important addition I included below). Is there a more elegant approach to achieve ...

The property or method 'startsWith' is not supported by this object

Regarding my webpack configuration: { "presets": [ ["env", { "targets": { "browsers": [">0.1%", "last 4 versions", "not ie <= 9"] } }] ] } However, I encountered a problem specifically in Internet Explorer: Ther ...

Utilizing Reactjs and Php to Send and Retrieve Form Data

I am currently working with Reactjs (Nextjs) and PHP. I am trying to send form data using Axios, but I am facing an issue where I am unable to retrieve any parameter on the API side. How can I resolve this problem? Below is my current code: const handleSu ...

How to ensure the table fits perfectly on the screen using JQueryMobile and Cordova?

I've been working on a JavaScript function that creates a dynamic page and displays data fetched from a database. However, I've encountered an issue where the displayed data overflows past the width of the mobile screen. Is there a way to ensure ...

Is it better to use regexp.test or string.replace first in my code?

When looking to replace certain parts of a string, is it better to use the replace method directly or first check if there is a match and then perform the replacement? var r1 = /"\+((:?[\w\.]+)(:?(:?\()(:?.*?)(:?\))|$){0,1})\ ...

The glitch in jQuery's animate function callback

In my code to animate the sliding out of a div, I encountered an issue: var current = $('.s_text:visible'); current.animate({ right: 1014, opacity:0, },{queue: false, duration:2000}, function() { current.hide(); }); Strangely, the callbac ...

Store the encoded data in a variable

After looking at some examples, I attempted to create my own solution but encountered an issue with the Promise being stuck in a "pending" state. My goal is to store base 64 data into a variable named base64. Can anyone offer guidance on what's wrong ...

Sorting and Uploading Images made Easy with Drag-and-Drop Functionality

Currently, I am developing a webpage and exploring the option of implementing a drag-and-drop image upload system that allows users to remove and sort images before uploading. I am seeking your opinion on this matter. I am concerned about potential issue ...

Error: Invalid JSON format - token 'o' found at index 1

Working with a type class in my controller, I am currently parsing data and receiving it in the following format: { "data": { "userList":[ { "id":1, "name":"soni ...

Despite calling this.setState to update my state, the render() method is still displaying the previous values

class EditLocation extends Component { constructor(props) { super(); this.state = { LocationId: '', locationOptions: [], } this.baseState = this.state; this.findLocationById = this ...

How to assign a value to an array within a form in Angular 8

I'm facing an issue with my Angular 8 edit form that utilizes a form array. When I navigate to the page, the form array is not populated with values as expected. Can anyone help me identify and solve this problem? ngOnInit(): void { // Fetc ...

What is the best way to call a function within another function only when a certain div is not clicked?

Throughout my code, I am utilizing the campusInfo(id) function. This particular function, in turn, calls another function named campusInfo_2(HouseID). One scenario where I am invoking campusInfo(id) is when a specific div is clicked. In this instance, I ...

"Following successful POST login and session storage in MongoDB, the session is unable to be accessed due

When sending login data by POST with the credentials: 'include' option from client server 5500 to backend server 3000, I ensure that my session data is properly stored in MongoDB thanks to the use of 'connect-mongodb-session'. In the ba ...

Need assistance with debugging the current solution for the todo App using Commander or considering a different approach with Readline and Event Emitter?

I'm currently working on developing a CLI for a Node.js exclusive todo application using the commander and conf modules within Node.js, along with chalk to add color to the output. I've encountered some issues that I'm unsure how to resolve: ...

Is there a way to enhance the Download File dialog with an additional option?

I want to develop an extension for a specific file type, and I'm interested in including a "Send to MyAddonName" feature in the download file dialog, alongside the "Open with" and "Save file" options. Just to clarify, I don't mean the Download Ma ...

What is the best way to retrieve an attribute from an object dynamically using JavaScript?

Inside my object, I have the following values: obj.resposta1 obj.resposta2 obj.resposta3 obj.resposta4 How can I access each value inside a loop like this: for ( var int = 1; int < 5; int++) Thank you, Celso ...