Jump to content

php header include and javascript


sungpeng

Recommended Posts

Hi check did anyone encounter this problem?  I put javascript dropdown menu on php header. Then I use "include" to call out the header. PHP doesn't read the javascript in the header. When I just view the header page itself, there is no problem. Why is that so?

Link to comment
Share on other sites

Name of the below save as header.php               

    



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">




<script type="text/javascript" src="dropdown.js"></script>

<style type="text/css">

body { font-size: 0.7em; }
h3   { font-size: 1.6em; margin: 0px; }

a.sample_attach, a.sample_attach:visited, div.sample_attach
{
  display: block;
  width:   100px;

  border:  1px solid black;
  padding: 2px 5px;

  background: #FFFFEE;

  text-decoration: none;
  font-family: Verdana, Sans-Sherif;
  font-weight: 900;
  font-size: 1.0em;
  color:   #008000;
}

a.sample_attach, a.sample_attach:visited { border-bottom: none; }
div#sample_attach_menu_child             { border-bottom: 1px solid black; }

form.sample_attach
{
  position: absolute;
  visibility: hidden;

  border:  1px solid black;
  padding: 0px 5px 2px 5px;

  background: #FFFFEE;
}

form.sample_attach b
{
  font-family: Verdana, Sans-Sherif;
  font-weight: 900;
  font-size: 1.1em;
}

input.sample_attach { margin: 1px 0px; width: 170px; }

</style>


</head>

<body>

<br /><br />

<div id="sample_attach_menu_parent" class="sample_attach">Main Menu</div>
<div id="sample_attach_menu_child">
<a class="sample_attach" href="javascript:alert('Item 1');">Item 1</a>
<a class="sample_attach" href="javascript:alert('Item 2');">Item 2</a>
<a class="sample_attach" href="javascript:alert('Item 3');">Item 3</a>
</div>

<script type="text/javascript">
at_attach("sample_attach_menu_parent", "sample_attach_menu_child", "hover", "y", "pointer");
</script>

</body>

</html>    

                 

 

 

 

Save below as dropdown.js



function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** at_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

 

When you just view the header.php page, the dropdown menu work nicely. Question is when you use

include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/header.php");

to call out the header, the javascript won't work anymore?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.