• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

need to use php in my javascript drop down menu

Hi

I need to use PHP in my Javascript dropdown menu.

I'm linking to an external js file and calling it php which seems to be working (I'm still seeing my hardcoded drop down menu items).

<script language="JavaScript" type="text/JavaScript" src="js/main-dd.php">

but, i can't figure out how to dynamically generate the drop down items - is there a way to do this without drastically rewriting everything?
function mmLoadMenus() {
  if (window.mm_menu_0827105605_0) return;
                  window.mm_menu_0827105605_0 = new Menu("root",194,17,"Arial, Helvetica, sans-serif",11,"#999999","#0067b1","#FFFFFF","#FFFFFF","left","middle",3,0,300,-5,7,true,false,true,4,true,true);
  mm_menu_0827105605_0.addMenuItem("<?php echo $row_rsMenuCD['name']; ?>","location='commercial.php'");

Open in new window

0
phillystyle123
Asked:
phillystyle123
  • 2
  • 2
1 Solution
 
Ray PaseurCommented:
We would need to see a little more of what you have tried so far in order to help.

This statement is fine:
<script language="JavaScript" type="text/JavaScript" src="js/main-dd.php">

It requires your PHP code to generate JavaScript instead of HTML.  That is no problem at all, just requires the right level of attention to detail in the coding and testing.

Best regards, ~Ray
0
 
phillystyle123Author Commented:
Thanks for your help with this Ray:

here's the front end where I'm testing this drop down:

http://mlaclaims.com/dds.php

mouseover "Commercial Division" on the top nav. Notice the first menu item is missing. This is the one I'm trying to dynamically generate (hoping to dynamically generate all of them obviously but this is my test)

here's what i'm using to call the drop down:

<div id="topNavButtonBG"><a href="commercial.php"><img src="images/mla2-commercial-division<?php if ($crumb=="disaster") {echo "-over";} else {echo "";}?>.gif" alt="Commercial Division" name="CommDiv" width="50" height="21" border="0" id="CommDiv" onMouseOver="MM_swapImage('CommDiv','','images/mla2-commercial-division-over.gif',1);MM_showMenu(window.mm_menu_0827105605_0,0,31,null,'CommDiv')" onMouseOut="MM_swapImgRestore();MM_startTimeout();"></a></div>

I've built a query into the dds.php page:

mysql_select_db($database_mlaclaimsweb, $mlaclaimsweb);
$query_rsMenuCD = "SELECT menutype, name FROM jos_menu WHERE menutype = 'Commercial-Division'";
$rsMenuCD = mysql_query($query_rsMenuCD, $mlaclaimsweb) or die(mysql_error());
$row_rsMenuCD = mysql_fetch_assoc($rsMenuCD);
$totalRows_rsMenuCD = mysql_num_rows($rsMenuCD);

and lastly i've tried to output the menu name in my javascript (main-dd.php) - see attached

// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
 
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function mmLoadMenus() {
  if (window.mm_menu_0827105605_0) return;
                  window.mm_menu_0827105605_0 = new Menu("root",194,17,"Arial, Helvetica, sans-serif",11,"#999999","#0067b1","#FFFFFF","#FFFFFF","left","middle",3,0,300,-5,7,true,false,true,4,true,true);
  mm_menu_0827105605_0.addMenuItem("<?php echo $row_rsMenuCD['name']; ?>","location='commercial.php'");
  mm_menu_0827105605_0.addMenuItem("Frequently Asked Questions","location='faqs.php'");
  mm_menu_0827105605_0.addMenuItem("Case Studies","location='case-study.php?catid=6'");
  mm_menu_0827105605_0.addMenuItem("Commercial Clients","location='clients.php'");
  mm_menu_0827105605_0.addMenuItem("Prepared Client Program","location='prepared.php'");
   mm_menu_0827105605_0.hideOnMouseOut=true;
   mm_menu_0827105605_0.bgColor='#000000';
   mm_menu_0827105605_0.menuBorder=0;
   mm_menu_0827105605_0.menuLiteBgColor='#D4D0C8';
   mm_menu_0827105605_0.menuBorderBgColor='#FFFFFF';
window.mm_menu_0827160650_0 = new Menu("root",62,17,"Arial, Helvetica, sans-serif",11,"#999999","#0033CC","#FFFFFF","#FFFFFF","left","middle",3,0,300,-5,7,true,false,true,4,true,true);
  mm_menu_0827160650_0.addMenuItem("bla&nbsp;bla","location='heytyere.html'");
   mm_menu_0827160650_0.hideOnMouseOut=true;
   mm_menu_0827160650_0.bgColor='#FFFFFF';
   mm_menu_0827160650_0.menuBorder=1;
   mm_menu_0827160650_0.menuLiteBgColor='#FFFFFF';
   mm_menu_0827160650_0.menuBorderBgColor='#FFFFFF';
 
  window.mm_menu_0827160650_0 = new Menu("root",81,17,"Arial, Helvetica, sans-serif",11,"#999999","#0033CC","#FFFFFF","#FFFFFF","left","middle",3,0,300,-5,7,true,false,true,4,true,true);
  mm_menu_0827160650_0.addMenuItem("New&nbsp;item","location='bla.html'");
   mm_menu_0827160650_0.hideOnMouseOut=true;
   mm_menu_0827160650_0.bgColor='#FFFFFF';
   mm_menu_0827160650_0.menuBorder=1;
   mm_menu_0827160650_0.menuLiteBgColor='#FFFFFF';
   mm_menu_0827160650_0.menuBorderBgColor='#FFFFFF';
   
   window.mm_menu_0918041557_0 = new Menu("root",194,17,"Arial, Helvetica, sans-serif",11,"#999999","#0067b1","#FFFFFF","#FFFFFF","left","middle",3,0,300,-5,7,true,false,true,4,true,true);
  mm_menu_0918041557_0.addMenuItem("When Disaster Strikes","location='residential-disaster.php'");
  mm_menu_0918041557_0.addMenuItem("Frequently Asked Questions","location='residential-faqs.php'");
  mm_menu_0918041557_0.addMenuItem("Sample Claims","location='residential.php'");
   mm_menu_0918041557_0.hideOnMouseOut=true;
   mm_menu_0918041557_0.bgColor='#000000';
   mm_menu_0918041557_0.menuBorder=0;
   mm_menu_0918041557_0.menuLiteBgColor='#D4D0C8';
   mm_menu_0918041557_0.menuBorderBgColor='#FFFFFF';
 
  
 
   
   
 
mm_menu_0827160650_0.writeMenus();
 
} // mmLoadMenus()

Open in new window

0
 
Ray PaseurCommented:
On this page:
http://mlaclaims.com/dds.php

The "Commercial Division" line says this (see top line in code snippet)


On this page:
http://mlaclaims.com/commercial.php

See next line in code snippet.

It looks like both lines are rotating gif images into display?  It also looks incredibly complicated to me.

From where I sit, it looks like you could be debugging this for a long time.  I recommend that you look at the menus available from "dynamic drive" - they are peer-reviewed and configurable.  It's a great script library.
http://www.dynamicdrive.com/

Good luck, ~Ray
<div id="topNavButtonBG"><a href="commercial.php"><img src="images/mla2-commercial-division.gif" alt="Commercial Division" name="CommDiv" width="50" height="21" border="0" id="CommDiv" onMouseOver="MM_swapImage('CommDiv','','images/mla2-commercial-division-over.gif',1);MM_showMenu(window.mm_menu_0827105605_0,0,31,null,'CommDiv')" onMouseOut="MM_swapImgRestore();MM_startTimeout();"></a></div>
 
<div id="topNavButtonBG"><a href="commercial.php"><img src="images/mla2-commercial-division-over.gif" alt="Commercial Division" name="CommDiv" width="50" height="21" border="0" id="CommDiv" onMouseOver="MM_swapImage('CommDiv','','images/mla2-commercial-division-over.gif',1);MM_showMenu(window.mm_menu_0827105605_0,0,31,null,'CommDiv')" onMouseOut="MM_swapImgRestore();MM_startTimeout();"></a></div>

Open in new window

0
 
phillystyle123Author Commented:
that's a great idea - probably much simpler than this clunky dw dd.

thanks ray
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now