GregL83 Posted September 25, 2007 Share Posted September 25, 2007 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 More sharing options...
jesh Posted September 25, 2007 Share Posted September 25, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.