K
Konrad Ciborowski
Hi guys,
It is my first time on this group and I'm hoping
some good people will help me overcome my problem.
JavaScript veterans have probably seen it before
but I am kind puzzled by this one. Perhaps more surfing
through the net might be enough to find a solution but it this
can of worms occurred to me in a complex framework and it took
me a few hours merely to isolate the problem.
Here is my problem in a nutshell. Below is
my tiny web page. Please copy and paste its contents
and save as test.html and then open it in IE 6
(I don't know about other browsers but for me
it has to work under IE 6).
You will see a very simple site. Then
please do the following
Scenario #1
1. Press Submit.
2. The Submit button will turn grey.
3. An alert window will pop-up, please press
space to close it.
4. Wait patiently until the page reappears
with the Submit button looking normally.
Looking at the source code it is
obvious what happened. When Submit was clicked
the submitForm() function was called which deactivated
the button and displayed the alert.
The for loop does nothing interesting,
it is there simply to make the execution of the
function last a while (a few seconds - this the key
component of the equation). Then the form
is submitted and as its action points to the form itself
the page reappears all right.
Scenario #2
1. Press Submit.
2. The Submit button will turn grey.
3. An alert window will pop-up, please press
space to close it.
4. Without waiting please click immediately the
Submit button again even though it is greyed out
and deactive.
What will happen is that the page will reappear but
then the alert will pop up again meaning that
the submitForm() function has been re-entered.
This is something I don't want.
I want the submitForm() to be run only once.
It seems to me that when the page is reloaded the browser
somehow remembers that the button was pressed
on the previous page. Can anyone help me on
how to get rid of this double call of the
submitForm() function? Because right now
it acts almots like a double submit.
Konrad Ciborowski
Kraków, Poland
======== test.html =====================
<HTML>
<BODY>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function submitForm() {
document.getElementById('guzik').disabled = true;
alert("I am here!");
for (var z = 1; z < 10000; z++) {
var leftSelect = document.getElementById('select1');
for (i = 0; i < leftSelect.options.length; i++) {
if (leftSelect.options.selected) {
leftSelect.options.selected = false;
} else {
leftSelect.options.selected = true;
}
}
}
for (i = 0; i < leftSelect.options.length; i++) {
leftSelect.options.selected = true;
}
document.getElementById('testowa').submit();
}
</SCRIPT>
<FORM name=testowa id=testowa action=test.html>
<SELECT NAME="toppings" id="select1" MULTIPLE SIZE=5>
<OPTION VALUE="mushrooms">mushrooms</OPTION>
<OPTION VALUE="greenpeppers">green peppers</OPTION>
<OPTION VALUE="onions">onions</OPTION>
<OPTION VALUE="tomatoes">tomatoes</OPTION>
<OPTION VALUE="olives">olives</OPTION>
</SELECT>
<BR>
<INPUT type=button id=guzik value=Submit onClick="submitForm(); return
false;">
</FORM>
</BODY>
</HTML>
It is my first time on this group and I'm hoping
some good people will help me overcome my problem.
JavaScript veterans have probably seen it before
but I am kind puzzled by this one. Perhaps more surfing
through the net might be enough to find a solution but it this
can of worms occurred to me in a complex framework and it took
me a few hours merely to isolate the problem.
Here is my problem in a nutshell. Below is
my tiny web page. Please copy and paste its contents
and save as test.html and then open it in IE 6
(I don't know about other browsers but for me
it has to work under IE 6).
You will see a very simple site. Then
please do the following
Scenario #1
1. Press Submit.
2. The Submit button will turn grey.
3. An alert window will pop-up, please press
space to close it.
4. Wait patiently until the page reappears
with the Submit button looking normally.
Looking at the source code it is
obvious what happened. When Submit was clicked
the submitForm() function was called which deactivated
the button and displayed the alert.
The for loop does nothing interesting,
it is there simply to make the execution of the
function last a while (a few seconds - this the key
component of the equation). Then the form
is submitted and as its action points to the form itself
the page reappears all right.
Scenario #2
1. Press Submit.
2. The Submit button will turn grey.
3. An alert window will pop-up, please press
space to close it.
4. Without waiting please click immediately the
Submit button again even though it is greyed out
and deactive.
What will happen is that the page will reappear but
then the alert will pop up again meaning that
the submitForm() function has been re-entered.
This is something I don't want.
I want the submitForm() to be run only once.
It seems to me that when the page is reloaded the browser
somehow remembers that the button was pressed
on the previous page. Can anyone help me on
how to get rid of this double call of the
submitForm() function? Because right now
it acts almots like a double submit.
Konrad Ciborowski
Kraków, Poland
======== test.html =====================
<HTML>
<BODY>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function submitForm() {
document.getElementById('guzik').disabled = true;
alert("I am here!");
for (var z = 1; z < 10000; z++) {
var leftSelect = document.getElementById('select1');
for (i = 0; i < leftSelect.options.length; i++) {
if (leftSelect.options.selected) {
leftSelect.options.selected = false;
} else {
leftSelect.options.selected = true;
}
}
}
for (i = 0; i < leftSelect.options.length; i++) {
leftSelect.options.selected = true;
}
document.getElementById('testowa').submit();
}
</SCRIPT>
<FORM name=testowa id=testowa action=test.html>
<SELECT NAME="toppings" id="select1" MULTIPLE SIZE=5>
<OPTION VALUE="mushrooms">mushrooms</OPTION>
<OPTION VALUE="greenpeppers">green peppers</OPTION>
<OPTION VALUE="onions">onions</OPTION>
<OPTION VALUE="tomatoes">tomatoes</OPTION>
<OPTION VALUE="olives">olives</OPTION>
</SELECT>
<BR>
<INPUT type=button id=guzik value=Submit onClick="submitForm(); return
false;">
</FORM>
</BODY>
</HTML>