location not working to load new CSP page

I have a web application and one of the CSP pages contains the following snippets:

<script language='javascript'>
function SubmitForm(pid,sid) {
//code to process form

alert ("study saved");

self.document.location="newpage.csp";

}

</script>

<form name="Studyform"  method="post" onsubmit='return SubmitForm(#(SubjObj.%Id())#,#(StudyObj.%Id())#);' >
<!-- form contents -->

</form>

The form is correctly processed, the object is saved, and the alert appears, but the new page does not get loaded and I cannot figure out why.

Any suggestions?

  • 0
  • 0
  • 162
  • 3
  • 2

Answers

In the OnSubmit you use a 'Return function' (which is unusual). Your function returns nothing, a 'false' by default, so I suspect the complete submit is cancelled because of the 'return false'. But that's only a guess.

OK, thank you.

If that is an unusual technique, what is the more standard method?

I just tested your suggestion.  When the function returns 'true', the behavior is the same (it does not load the new page).  However, when the function returns 'false', I do get the desired behavior -- it loads the new page.  Does that make sense?

More standard is just to call a function: onsubmit='function(...);' without the 'return'

It seems just to work the other way around then I anticipated, I haven't had any time to actually try it

Thank you Herman, I appreciate the help.

When I change the form attribute to onsubmit ='SubmitForm()' then it stays on the current page after the form is processed regardless of whether the SubmitForm function returns 'true' or 'false'.

So far, the only way I've been successful getting it to go to the new page is when I use onsubmit='return SubmitForm()' and then return false at the end of the SubmitForm function. 

I probably have something else wrong that is causing this behavior.

I'd probably do it something like this:

<html>
<head>
<title> Cache Server Page </title>

<script language='javascript'>
function SubmitForm(pid,sid) {
var elem document.getElementsByName("Studyform");
elem[0].submit;
//code to process form

alert ("study saved");
self.document.location="newpage.csp";
}

</script>
</head>

<body>
<form name="Studyform">
<input type="button" name="submit" value="submit" onclick="javascript:SubmitForm(#(SubjObj.%Id())#,#(StudyObj.%Id())#);">

</form>
</body>
</html>

or this, which is very similar apart from the use of 'id' rather than 'name'

<html>
<head>
<title> Cache Server Page </title>

<script language='javascript'>
function SubmitForm(pid,sid) {
var elem document.getElementById("Studyform");
elem.submit;
//code to process form

alert ("study saved");
self.document.location="newpage.csp";
}

</script>
</head>

<body>
<form id="Studyform">
<input type="button" name="submit" value="submit" onclick="javascript:SubmitForm(#(SubjObj.%Id())#,#(StudyObj.%Id())#);">

</form>
</body>
</html>