Link to home
Start Free TrialLog in
Avatar of mxjijo
mxjijo

asked on

DHTML - Disable parent window


Hi all,
    I have a sitiation where I need to make sure the user will not do anything on the parent window while a popup window
is running. There are a handful of fields in the parent window, so disabling one one one would be impossible. One way
to do this may be a show/hide with a div tag. But, being a beginner,  I'm just wondering whether there is a better way to do this .

thanks
~j
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

You can disable the complette form by disable the form object.
Here an example:

<html>
<head>
<title>Zvonko &#42;</title>
</head>
<body>
<form>
<input type="text" name="myField">
<input type="submit">
</form>
<a href="#" onClick="document.forms[0].disabled=true;return false">Disable</a>
<a href="#" onClick="document.forms[0].disabled=false;return false">Enable</a>
</body>
</html>

Avatar of mxjijo
mxjijo

ASKER


thanks for the quick response.
I have several fields outside the form.
Is it possible to disable the document itself ?
Fields outside the form???
What do you call fields what is NOT in a form?
Loop trough all forms on the document and disable all forms:

<html>
<head>
<title>Zvonko &#42;</title>
</head>
<body>
<form>
<input type="text" name="myField1">
<input type="submit">
</form>
<form>
<input type="text" name="myField2">
<input type="submit">
</form>
<form>
<input type="text" name="myField3">
<input type="submit">
</form>
<a href="#" onClick="f=document.forms;for(var i=0;i<f.length;i++)f[i].disabled=true;return false">Disable</a>
<a href="#" onClick="f=document.forms;for(var i=0;i<f.length;i++)f[i].disabled=false;return false">Enable</a>
</body>
</html>

Avatar of mxjijo

ASKER


I have a bunch of links outside the form
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mxjijo

ASKER


> What do you call fields what is NOT in a form?
>  In your question you did NOT mention that.


>> I have several fields outside the form.

     you don't count that ?? :)
Fields and Links are separate collections.

See you.
Avatar of mxjijo

ASKER



hmm.. I took another look at your code.. .
don't you think ALL the links in your are STILL inside a form ??
When I said I have fields (and links) outside form - I DID NOT mean they inside another form :)
I slightly modified your code to add a link OUTSIDE ALL froms - can you disable that ??

<html>
<head>
<title>Zvonko &#42;</title>
</head>
<body>

<a href="https://www.experts-exchange.com/">This is outside ALL forms</>

<form>
<input type="text" name="myField1">
<input type="submit">
<a href="https://www.experts-exchange.com/">EE</>
</form>


<form>
<input type="text" name="myField2">
<input type="submit">
<a href="https://www.experts-exchange.com/">EE</>
</form>

<form>
<input type="text" name="myField3">
<input type="submit">
<a href="https://www.experts-exchange.com/">EE</>
</form>

<script>
var pop=window.open("","control","top=120,left=350,width=200,height=100");
with(pop.document){
  open();
  write('<html><head><title>Zvonko &#42;</title></head><body>');
  write('<center>');
  write('<a href="#" onClick="opener.document.body.onclick=function(){return false};');
  write('f=opener.document.forms;for(var i=0;i<f.length;i++)f[i].disabled=true;return false">Disable</a>');
  write('<br>');
  write('<a href="#" onClick="opener.document.body.onclick=null;');
  write('f=opener.document.forms;for(var i=0;i<f.length;i++)f[i].disabled=false;return false">Enable</a>');
  write('</center>');
  write('</body></html>');
  close();
}
pop.focus();
</script>
</body>
</html>

LOL :-)

Collections are this:
document.forms
document.links

And both can be spread across the page.
So even when links are inside the form section does they NOT belong to the form elements.

Avatar of mxjijo

ASKER


thanks.. I'm not that famillier with html terminology/structure
Now I see your question!
The link is not clickable also when it does not look like disabled.
And it seams forms influence also elements inside the form section which do not belong to form collection to look like disabled. But withouth the clickk blocker would that disabled looking links stay active.