What im trying to is something a little weird and different. The code below just creates a few divs, css, and more javascript using javascript. Everything works fine besides the javascript. For some reason i can not get it to work.
What im trying to do is make the linksonclick to view on the on the div element that is also created on the other statement.Code:<a class="fl" onClick="new_text(\'calculator\')">Calculator</a><br /><a class="fl" onClick="new_text(\'train\')">Train</a>
i am using this javascript to make it appear on the other one:
Any help would be great. I dont understand why this wont workCode:function new_text(value) {x = document.getElementById(value);y = document.getElementById("hidden");y.style.display = "block"; if(y.innerHTML != x.innerHTML){y.innerHTML = x.innerHTML;}}
What is going wrong: When i click one anchor it works the first time; however, when i click the second it fails to work and change the innerHTML. Not sure why it wont change it tho :/
Thanks in advance.
Code:<html> <head> <script> function load_test(){ //creates StyleSheet var ss1 = document.createElement('style'); var def = 'body {background-color:red;} .main_div {width:200px; border:1px solid white; position:absolute; top:150px; right:0px;background-color:black;color:white;text-indent: 2px;} .links {width:100%;border-top:1px solid white;padding:0;margin-top:2px;} a.fl {cursor:pointer;text-decoration:underline;color:red;} a.fl:hover {text-decoration:none;color:blue;} #hidden {display:none; background-color:black; color:red; width:200px;position:absolute;top:150px;left:0px;} .hidden_test {display:none;}'; ss1.setAttribute("type", "text/css"); var hh1 = document.getElementsByTagName('head')[0]; hh1.appendChild(ss1); if (ss1.styleSheet) { // IE ss1.styleSheet.cssText = def; } else { // the world var tt1 = document.createTextNode(def); ss1.appendChild(tt1); } //creates javascript var ss = document.createElement('script'); var scr = 'function new_text(value) {x = document.getElementById(value);y = document.getElementById("hidden");y.style.display = "block"; if(y.innerHTML != x.innerHTML){y.innerHTML = x.innerHTML;}}'; ss.text = scr; var hh = document.getElementsByTagName('head')[0]; hh.appendChild(ss); //creates Main Div var main_div = document.createElement('div'); var string = 'This is adding extra elements to a page that a user created! It is very simple to use.'; var links = '<div class="links"><a class="fl" onClick="new_text(\'calculator\')">Calculator</a><br /><a class="fl" onClick="new_text(\'train\')">Train</a></div>'; main_div.className = 'main_div'; var final = string+links main_div.innerHTML = final; document.body.appendChild(main_div); //creates sub div var sub_div = document.createElement('div'); var content = 'Something'; var objs = '<div id="calculator" class="hidden">This is the calculator</div><div id="train" class="hidden">This is the train command</div>'; sub_div.setAttribute("id", "hidden"); sub_div.innerHTML = content+objs; document.body.appendChild(sub_div); } </script> </head> <body onload="load_test()"> <a class="style" href="">Something</a> </body> </html>



Reply With Quote

Bookmarks