PDA

View Full Version : Passing to a Function



locbtran
09-23-2011, 07:49 AM
How do I pass an id to a function??
Or is this even possible.


<html>
<head>
<title></title>
<script type="text/javascript">

function init(){
display(addText1);
display(addText2);
display(addText3);
display(addText4);
}

function display(var myText){
var newText = '<h2>' + "Will this change anything..." + '</h2>';

document.getElementById('myText').innerHTML = newText;
}
</script>
</head>
<body onload="init()">

<div id="addText1"></div>
<div id="addText2"></div>
<div id="addText3"></div>
<div id="addText4"></div>
</body>
</html>

Minos
09-23-2011, 01:43 PM
Well, the way you are doing it:



function init(){
display("addText1");
display("addText2");
display("addText3");
display("addText4");
}

function display(myText){
var newText = '<h2>' + "Will this change anything..." + '</h2>';

document.getElementById(myText).innerHTML = newText;
}