Question
· Jul 24, 2018

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?

Discussion (5)0
Log in or sign up to continue

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>