hide and show popup menu
-
Dear All, I have very simple statements which popsup a menu as bellow
var ie5=document.all && !window.opera
var ns6=document.getElementByIdif (ie5||ns6)
document.write('<div id="popitmenu"></div>')
function showmenu(e, which, optWidth)
{
menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
menuobj.innerHTML=which
/*
process links and others here then finaly display it
*/
menuobj.style.visibility="visible";
return false
}
function hidemenu()
{
var div = document.getElementById('popitmenu');
if (div)
div.style.visibility="hidden";
}
if (ie5||ns6)
document.onclick=hidemenu;
<body style="width:100%; height:100%">
<form id="form1" runat="server">
<div>
<a id="a" onclick="return showmenu(event,linkset[1], '180px');">Click here</a>
</div>
</form>
</body>every time i click on "Click here" which displays popupmenu it suddenly hides, I debugged the statements and I got that every time the function hidemenu() is executed. as I am assigning hidemenu function to body click event which means, If i click at body the popupmenu should hide, but the question is here, If i am clicking at "Click here" why the hidemenu is called, or how I can hide the popupmenu. simply, when I click at click here the popup should appear but when i am clicking at other places the popup should hide, how to achive it in above?
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
Dear All, I have very simple statements which popsup a menu as bellow
var ie5=document.all && !window.opera
var ns6=document.getElementByIdif (ie5||ns6)
document.write('<div id="popitmenu"></div>')
function showmenu(e, which, optWidth)
{
menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
menuobj.innerHTML=which
/*
process links and others here then finaly display it
*/
menuobj.style.visibility="visible";
return false
}
function hidemenu()
{
var div = document.getElementById('popitmenu');
if (div)
div.style.visibility="hidden";
}
if (ie5||ns6)
document.onclick=hidemenu;
<body style="width:100%; height:100%">
<form id="form1" runat="server">
<div>
<a id="a" onclick="return showmenu(event,linkset[1], '180px');">Click here</a>
</div>
</form>
</body>every time i click on "Click here" which displays popupmenu it suddenly hides, I debugged the statements and I got that every time the function hidemenu() is executed. as I am assigning hidemenu function to body click event which means, If i click at body the popupmenu should hide, but the question is here, If i am clicking at "Click here" why the hidemenu is called, or how I can hide the popupmenu. simply, when I click at click here the popup should appear but when i am clicking at other places the popup should hide, how to achive it in above?
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
Abdul Rahman Hamidy wrote:
If i am clicking at "Click here" why the hidemenu is called, or how I can hide the popupmenu.
Because, Click here is a part of the page body (its in it!)
Abdul Rahman Hamidy wrote:
simply, when I click at click here the popup should appear but when i am clicking at other places the popup should hide, how to achive it in above?
On body click, call a javascript method where you can check if the click was on 'Click Here' div tag, if so, dont do anything or else hide it.
-
Dear All, I have very simple statements which popsup a menu as bellow
var ie5=document.all && !window.opera
var ns6=document.getElementByIdif (ie5||ns6)
document.write('<div id="popitmenu"></div>')
function showmenu(e, which, optWidth)
{
menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
menuobj.innerHTML=which
/*
process links and others here then finaly display it
*/
menuobj.style.visibility="visible";
return false
}
function hidemenu()
{
var div = document.getElementById('popitmenu');
if (div)
div.style.visibility="hidden";
}
if (ie5||ns6)
document.onclick=hidemenu;
<body style="width:100%; height:100%">
<form id="form1" runat="server">
<div>
<a id="a" onclick="return showmenu(event,linkset[1], '180px');">Click here</a>
</div>
</form>
</body>every time i click on "Click here" which displays popupmenu it suddenly hides, I debugged the statements and I got that every time the function hidemenu() is executed. as I am assigning hidemenu function to body click event which means, If i click at body the popupmenu should hide, but the question is here, If i am clicking at "Click here" why the hidemenu is called, or how I can hide the popupmenu. simply, when I click at click here the popup should appear but when i am clicking at other places the popup should hide, how to achive it in above?
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
Here is a simple example which i believe accomplishes what you want ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script>linkset = new Array("hiyas","sup");
showmenu = function(thiss){
pop = document.getElementById("popmenu");
pop.innerHTML = "px = "+ thiss.px + " link = " + linkset[thiss.link]
pop.style.visibility = 'visible';}
hide = function(e){
if(e){
id = e.target.id}
else{
id = event.srcElement.id}
if(id !="show"){
document.getElementById("popmenu").style.visibility = 'hidden';}
}document.onclick=hide;
</script></head>
<body><form id="form1" runat="server"> <div> <a id="show" onclick="this.px='180px';this.link='1';showmenu(this)" > Click here </a><br> <a id="show" onclick="this.px='90px';this.link='0';showmenu(this)" > Click here </a> <div id="popmenu">Hello Im a menu</div> </div> </form> </body> </html>
-
Here is a simple example which i believe accomplishes what you want ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script>linkset = new Array("hiyas","sup");
showmenu = function(thiss){
pop = document.getElementById("popmenu");
pop.innerHTML = "px = "+ thiss.px + " link = " + linkset[thiss.link]
pop.style.visibility = 'visible';}
hide = function(e){
if(e){
id = e.target.id}
else{
id = event.srcElement.id}
if(id !="show"){
document.getElementById("popmenu").style.visibility = 'hidden';}
}document.onclick=hide;
</script></head>
<body><form id="form1" runat="server"> <div> <a id="show" onclick="this.px='180px';this.link='1';showmenu(this)" > Click here </a><br> <a id="show" onclick="this.px='90px';this.link='0';showmenu(this)" > Click here </a> <div id="popmenu">Hello Im a menu</div> </div> </form> </body> </html>
Thank you very much, the hide function could do the work.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
-
Thank you very much, the hide function could do the work.
Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan
Abdul Rahman Hamidy wrote:
Thank you very much, the hide function could do the work.
You are most welcome.