HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   how do I tell javascript what type of data I'm passing to a function? (http://www.howtoforge.com/forums/showthread.php?t=30579)

CMYK 24th January 2009 06:32

how do I tell javascript what type of data I'm passing to a function?
 
I have a function that goes like
Code:

function collapse(div) {
    var currentdiv = document.getElementById(div);
    currentdiv.style.zIndex = 3;
}

and code from the html document calls that function like
Code:

<a onclick="collapse('pictures')">pictures</a>
where pictures is the name of a <div> later on that had the id of pictures. Anyway, how can I tell Javascript that I'm passing a string so that the document.getELementById part will work? For example, the code will work if I write in document.getElementById("pictures");.

id10t 9th March 2009 17:18

javascript is typeless, so a variable holds whatever data of whatever type you stick into it

Change
Code:

document.getElementById(div)
to

Code:

document.getElementById($div)
Though... need the $div to references the variable created.


All times are GMT +2. The time now is 08:50.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.