document.Form.submit not submitting along with window.location at chrome and some IE 7 and 8
Hii Everyone , I am working on a project which is a kind of Survey. Here we navigate to different pages with another question. Once a question is asked ,user submit his response.After submitting the form , the page is redirected to next question. Below is the javascript code that enables it.
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('sur开发者_Go百科veyCode').value;
parent.SurveySummaryFrame.location="load_survey.php?scode="+scode + "&template=" + '<? echo $_GET["template"]?>';
}
window.location.href=nurl;
}
This code works fine with FF and IE6 at most of the time but fails with at times with IE7 and IE8 and every time with google chrome. If I remove window.location.href=nurl;
it submits it. but without commenting window.location.href=nurl;
it moves to next url without saving the user response.
My guess is due to high speed of processing of some browser it may go directly to next url without leaving the earlier part to submit. (Tough a weired idea I hope)
I need a solution badly to fix it. Can any one help
I would suggest you to submit the form using ajax and redirect after the ajax form is submitted successfully.
using jquery's post function is one of the simplest to do it. But you have to know jquery first. http://api.jquery.com/jQuery.post/
As for using Ajax; Why should we when the method .submit is already there and should do the job.
Anyways....
I was having the same problem. Everything worked in all browsers except google chrome.
I tried
document.NonJava.submit();
document.forms[0].submit();
and a number of other things.
This is what worked eventually worked:
var frm = document.getElementById('NonJava');
frm.submit();
Hey presto
精彩评论