Jump to content

Use Variable in document. .... line


GregL83

Recommended Posts

I am very new with javascript. I need to have a function that has the variable passed in it and used to locate a document element by id through a variable...something like thisfunction test(var){if(document.body.all.var.checked == true){document.getElementById(var).innerHTML=var}}<input type="checkbox" onClick="test('var1')" /><div id="var1"></div><input type="checkbox" onClick="test('var2')" /><div id="var2"></div>...Please Help! Thank you!

Link to comment
Share on other sites

You're pretty close:

<input type="checkbox" onClick="test(this, 'var1')" /><div id="var1"></div><input type="checkbox" onClick="test(this, 'var2')" /><div id="var2"></div><script type="text/javascript">function test(checkbox, id){	if(checkbox.checked)	{		document.getElementById(id).innerHTML = id;	}	else	{		document.getElementById(id).innerHTML = "";	}}</script>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...