OK , i am having an variable i , how i can execute/modify an element of the website? like var i=3; plus_i.style.visibility='hidden'; I am having an div plus3 and want to make it hidden ... The only problem is that the name of the <div> it's defined by the "var i=__" .... I known this has to do with something like eval,etc
I hope this code will help you, please try it on your browser: <head> <title>For DP</title> <style> <!-- div { border:solid 1px black; margin:10; padding:10; } --> </style> <script type="text/javascript"> function changeVisibility(whatToDo,i){ if(whatToDo == 'show') document.getElementById("plus"+i).style.visibility='visible'; if(whatToDo == 'hide') document.getElementById("plus"+i).style.visibility='hidden'; } </script> </head> <body> <form> Div: <input type="text" size="2" name="i" value="1" /> <br /> Action: <input type="radio" name="action" value="show"/> show <input type="radio" name="action" value="hide" checked="checked" /> hide <br /> <input type="submit" value="Apply" onclick="if(action[0].checked==true) a='show'; if(action[1].checked==true) a='hide'; changeVisibility(a,i.value);return false"/> </form> <hr /> <div id="plus1"><h1>#plus1</h1></div> <div id="plus2"><h1>#plus2</h1></div> <div id="plus3"><h1>#plus3</h1></div> </body></html> HTML:
Sorry... I updated the changeVisibility(whatToDo,i) function to : function changeVisibility(whatToDo,i){ if(whatToDo == 'show'){ document.getElementById("plus"+i).style.visibility='visible'; document.getElementById("plus"+i).style.display='block'; } if(whatToDo == 'hide'){ document.getElementById("plus"+i).style.visibility='hidden'; document.getElementById("plus"+i).style.display='none'; } } HTML: