Disable controls

S

Sehboo

In my application, there are lot of processes which take several
seconds. What we want is that once user clicks on a button (or link or
whatever) and while we are processing that request, we don't want user
to do anything else on the page. We want to disable everything. I
have following javascript on all of my pages (which is supposed to
work), but it doesn't work.

<script language="JavaScript">
function ignoreinput() {
return false;
}

function stop_input() {
window.attachEvent("onkeydown", ignoreinput);
window.attachEvent("onclick", ignoreinput);
}
</script>

<form name="_ctl0" method="post" action="mypage.aspx"
language="javascript" onsubmit="return stop_input(this);" id="_ctl0"
runat="server">
 
E

Evertjan.

Sehboo wrote on 19 dec 2006 in comp.lang.javascript:
In my application, there are lot of processes which take several
seconds. What we want is that once user clicks on a button (or link or
whatever) and while we are processing that request, we don't want user
to do anything else on the page. We want to disable everything. I
have following javascript on all of my pages (which is supposed to
work), but it doesn't work.

<script language="JavaScript">
function ignoreinput() {
return false;
}

function stop_input() {
window.attachEvent("onkeydown", ignoreinput);
window.attachEvent("onclick", ignoreinput);
}
</script>

<form name="_ctl0" method="post" action="mypage.aspx"
language="javascript" onsubmit="return stop_input(this);" id="_ctl0"
runat="server">

You want to run a form on the server?

There should be no one overthere, certainly no client user!
 
P

pcx99

Sehboo said:
In my application, there are lot of processes which take several
seconds. What we want is that once user clicks on a button (or link or
whatever) and while we are processing that request, we don't want user
to do anything else on the page. We want to disable everything. I
have following javascript on all of my pages (which is supposed to
work), but it doesn't work.

<script language="JavaScript">
function ignoreinput() {
return false;
}

function stop_input() {
window.attachEvent("onkeydown", ignoreinput);
window.attachEvent("onclick", ignoreinput);
}
</script>

<form name="_ctl0" method="post" action="mypage.aspx"
language="javascript" onsubmit="return stop_input(this);" id="_ctl0"
runat="server">

The problem, as I see it, is that when the form is submitted you stop
the input but the page is already reset because it's navigating to
mypage.aspx which means your event handlers are reset. The program flow
is going...

->Submit...
->Attach events....
->Browser navigates to mypage.aspx as it submits the data.
->The page is destroyed as the browser navigates to mypage.aspx
->The event handlers are destroyed when the page is destroyed.

So what you need to do is to have stop_input return false, this will
keep the submit from actually happening and the navigation event from
happening. Then use a small ajax call to submit the data. (You can
see an example of an ajax post call here:
http://www.hunlock.com/blogs/AJAX_POST-It_Notes -- fair warning, I wrote
the tutorial, it's my site ).

That will give you more control over what's going on while your data is
being processed. It will allow the data to be submitted while leaving
the page intact, which means the event handlers are going to be able to
work.

None of this will help you if the user starts messing with his browser's
forward/back buttons. You have a great deal of control over what the
user can do in the browser window but once the mouse leaves the content
area and hits the browser controls you're pretty much stuck which is
ironic because its designed that way to make sure the user can get
unstuck ;)

Hope that helps you out a bit.
 
S

Sehboo

does it matter?

Evertjan. said:
Sehboo wrote on 19 dec 2006 in comp.lang.javascript:


You want to run a form on the server?

There should be no one overthere, certainly no client user!
 
E

Evertjan.

Sehboo wrote on 19 dec 2006 in comp.lang.javascript:
[Please do not toppost on usenet]
does it matter?

Do you expect the users to travel to the server to fill in the form,
while the server might not even have a keyboard and screen?
 
N

news.isd.dp.ua

Sehboo пишет:
In my application, there are lot of processes which take several
seconds. What we want is that once user clicks on a button (or link or
whatever) and while we are processing that request, we don't want user
to do anything else on the page. We want to disable everything. I
have following javascript on all of my pages (which is supposed to
work), but it doesn't work.

<script language="JavaScript">
function ignoreinput() {
return false;
}

function stop_input() {
window.attachEvent("onkeydown", ignoreinput);
window.attachEvent("onclick", ignoreinput);
}
</script>

<form name="_ctl0" method="post" action="mypage.aspx"
language="javascript" onsubmit="return stop_input(this);" id="_ctl0"
runat="server">
As I see you use IExplorer. In this browser events always process from
inner elements to outer. That's why you script doesn't work.

You can disable mouse events by follow code:

var table = document.createElement("table");
table.style.width = 100%;
table.style.height = 100%;
var row = table.insertRow(0);
row.style.width = 100%;
row.style.height = 100%;
var cell = row.insertCell(0);
cell.style.width = 100%;
cell.style.height = 100%;
document.body.appendChild(table);

as for keyboard event you can move focus to some element, and disallow
change it before request processed.

For other browser (for example Firefox) you can use simple solution:
<script language="JavaScript">
function ignoreinput() {
return false;
}

function stop_input() {
document.addEventListener("keydown", ignoreinput, true);
document.addEventListener("click", ignoreinput, true);
}
</script>
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top