Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing in Varibles into an array

Status
Not open for further replies.
Jun 9, 2006
159
0
0
US
I have a pop up menu script. I want to dynimicaly pass in a parameter, but this method does not seem to be working for me:

Code:
<script type="text/javascript">

var mp3Id = "0";

var mp3Menu=new Array()
mp3Menu[0]='<a href="detail.aspx?id="'+mp3Id+'>Detail</a>'

function showmenu(e, which, optWidth, _mp3Id){
  mp3Id = _mp3Id 
  menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
  menuobj.innerHTML=which
  ...
}

<a onMouseover="showmenu(event,mp3Menu[0],'180px','69')">Details</a>

Shawn Molloy
Seattle, WA
 
I stop at this line and am not looking at the rest.
>mp3Menu[0]='<a href="detail.aspx?id="'+mp3Id+'>Detail</a>'
[tt]mp3Menu[0]='<a href="detail.aspx?id='+mp3Id+'">Detail</a>'[/tt]
 
Are you talking about the missing "? I fixed that but it still does not work...

Shawn Molloy
Seattle, WA
 
It does not work for other reasons from the script not shown. My advice is the only piece one can make on the script you've shown. What is ie5? where do you defined it? What is the popitMenu? No one here can see through the screen.
 
The "..." means that is code missing. Here is the complete code snippet (I got it from Dynamic Drive; I'm a .NET guy):

Code:
<script type="text/javascript">

/***********************************************
* Pop-it menu- © Dynamic Drive ([URL unfurl="true"]www.dynamicdrive.com)[/URL]
* This notice MUST stay intact for legal use
* Visit [URL unfurl="true"]http://www.dynamicdrive.com/[/URL] for full source code
***********************************************/

var defaultMenuWidth="20px" //set default menu width.
var mp3Id = "0";

var mp3Menu=new Array()
mp3Menu[0]='<a href="detail.aspx?id="'+mp3Id+'"><img class="menuIcon" src=\"[URL unfurl="true"]http://www.famfamfam.com/lab/icons/mini/icons/action_go.gif\">&nbsp;<strong>Listen</strong></a>'[/URL]
mp3Menu[0]+='<a href="[URL unfurl="true"]http://cnn.com"><img[/URL] class="menuIcon" src=\"[URL unfurl="true"]http://www.famfamfam.com/lab/icons/mini/icons/interface_installer.gif\">&nbsp;View[/URL] Details</a>'
mp3Menu[0]+='<a href="[URL unfurl="true"]http://cnn.com"><img[/URL] class="menuIcon" src=\"[URL unfurl="true"]http://www.famfamfam.com/lab/icons/mini/icons/action_stop.gif\">&nbsp;Remove[/URL] File</a>'
mp3Menu[0]+='<a href="[URL unfurl="true"]http://news.bbc.co.uk"><img[/URL] class="menuIcon" src=\"[URL unfurl="true"]http://www.famfamfam.com/lab/icons/mini/icons/icon_user.gif\">&nbsp;Send[/URL] to Friend</a>'
mp3Menu[0]+='<a href="[URL unfurl="true"]http://www.washingtonpost.com"><img[/URL] class="menuIcon" src=\"[URL unfurl="true"]http://www.famfamfam.com/lab/icons/mini/icons/folder_new.gif\">&nbsp;Add[/URL] to Torrent</a>'

////No need to edit beyond here

var ie5=document.all && !window.opera
var ns6=document.getElementById

if (ie5||ns6)
document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')

function iecompattest(){
return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function showmenu(e, which, optWidth, mp3Id){
if (!document.all&&!document.getElementById)
return
clearhidemenu()
menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
menuobj.innerHTML=which
menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth
menuobj.contentwidth=menuobj.offsetWidth
menuobj.contentheight=menuobj.offsetHeight
eventX=ie5? event.clientX : e.clientX
eventY=ie5? event.clientY : e.clientY
//Find out how close the mouse is to the corner of the window
var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px"
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px"
//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px"
else
menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px"
menuobj.style.visibility="visible"
return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.style.visibility="hidden"
}

function dynamichide(e){
if (ie5&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("hidemenu()",5000)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

if (ie5||ns6)
document.onclick=hidemenu

</script>

Shawn Molloy
Seattle, WA
 
I'm bumping this thread as I still haven't recieved a response. Basically I added these two paramters to a script I found on Dynamic Drive:

optWidth, _mp3Id

The mp3Id property inside the code is never populated... Any help would be most appricated.

Thanks,


Shawn Molloy
Seattle, WA
 
The first thing I would recommed is to download firefox and the firebug extension. This will help tremendously in troubleshooting.

Second, not only are you a .NET guy, but you're a VB.NET guy - hence the absence of semicolons ;) I'd recommend that you use the semicolon to delimit the end of each line of code - just to ensure that's not causing your error.

The mp3Id and width params are probably not being sent as arguments when you call the javascript function. I think Firebug+firefox will definitely help you solve the issue.

Let me know what error messages you get and post them here. It may also be easier if you post a URL where we can see the script in action.

________________________________________
Give a man a match, he'll be warm for a minute. But light him on fire, and he'll be warm for the rest of his life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top