Javascript Submit Problem

W

winstontuck

Hi

I am fairly new to javascript and html and I have the following
problem.

I have a page lets say page1. When something changes on page1 i set a
variable PossiblePageChanged to true. On page1 I have a link with
the
following properties : <A href="applypage1settings..and some
otherstuffhere" onclick="return CheckforPossibleChanges()">Page2</a>

When the user clicks in the link to Page2, it successfully detects
that the page has changed (if so) and give you the confirmation
message.
The problem is that if you click OK it does not always submit the
page1form (The httpserver does not always get the applypage1settings
request.)
It looks like it is normally from remote locations other than the
machine the http server is running on. Is this possible to do or is
there a different way.
Below is my javascript.



var PossiblePageChanged = false;

function CheckforPossibleChanges(){
if (PossiblePageChanged==true) {
conf = confirm('Click OK to your apply your changes or Cancel to
discard.')
if (conf==true){
return submitform();
}
}
}

function SubmitAForm(formname, formReference, ExtraParams){
var ExtraParamsStr ="";
if (ExtraParams) {if (ExtraParams!="") {ExtraParamsStr = "?" +
ExtraParams}};
form = document.getElementById(formname);
var s = form.action;
s = s.substring(s.length-32, s.length);
s = formReference+"?" + s + ExtraParamsStr;
form.action = s;
form.submit();
}

function submitform(){
if (CanApplyPage1Changes()==false) {return false;}
SubmitAForm("page1form", "applypage1settings")
}
 
W

wisestpotato

I have a page lets say page1. When something changes on page1 i set a
variable PossiblePageChanged to true. On page1 I have a link with
the
following properties : <A href="applypage1settings..and some
otherstuffhere" onclick="return CheckforPossibleChanges()">Page2</a>

You need to ensure that all the paths through your code will
ultimately return false. Otherwise, after the javascript has finished,
this link will be activated. Crucially, the link may well be followed
*before* the form is submitted. If that happens, the form will not
actually get submitted, because you've navigated away from the page
before it happened.

wp.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top