javascript - a utility to extract js for jsfiddle -
i have page .
if save html , js code in tags
but when put code in script tags in js part of jsfiddle.com, won't load.
code :
<html> <head> <script> var selele=0; var brindex=0; function addselectbox () { selele=selele+1; var spantag = document.createelement ("span"); spantag.setattribute("id",selele); var parentdiv = document.getelementbyid ("main"); var selectelement = document.createelement ("select"); var selectelement1 = document.createelement ("select"); var selectelement2= document.createelement ("select"); var selectelement3 = document.createelement ("select"); var arr=new array("stocks","mutualfunds"); var arr2=new array("individual","401k","ira"); var arr3=new array("contains","equals"); var arr4=new array("scrapedaccounttype","scrapedtransactiontype"); var textbox = document.createelement('input'); for(var i=0;i<arr.length;i++) { var option = new option (arr[i]); selectelement.options[selectelement.options.length] = option; } for(var i=0;i<arr2.length;i++) { var option = new option (arr2[i]); selectelement1.options[selectelement1.options.length] = option; } for(var i=0;i<arr3.length;i++) { var option = new option (arr3[i]); selectelement2.options[selectelement2.options.length] = option; } for(var i=0;i<arr4.length;i++) { var option = new option (arr4[i]); selectelement3.options[selectelement3.options.length] = option; } spantag.appendchild (selectelement); spantag.appendchild (selectelement1); spantag.appendchild (selectelement2); spantag.appendchild (selectelement3); spantag.appendchild (textbox); parentdiv.appendchild (spantag); linebreak(); } function removeselect() { var parentdiv = document.getelementbyid ("main"); var removetg = document.getelementbyid (selele); if(selele!=1) { parentdiv.removechild (removetg); selele=selele-1; }else { parentdiv.removechild (removetg); parentdiv.innerhtml=""; selele=selele-1; } removebreak(); } function linebreak() { brindex=brindex+1; var brtag =document.createelement ("br"); brtag.setattribute("id",brindex); var parentdiv = document.getelementbyid ("main"); parentdiv.appendchild (brtag); } function linespace() { var myelement = document.createelement("span"); myelement.innerhtml ="           "; var parentdiv = document.getelementbyid ("main"); parentdiv.appendchild (myelement); } function removebreak() { var myelement = document.getelementbyid(brindex); var parentdiv = document.getelementbyid ("main"); brindex=brindex-1; parentdiv.removechild (myelement); } function xmldata() { xmldoc=loadxmldoc("data.xml"); newel=xmldoc.createelement("edition"); x=xmldoc.getelementsbytagname("span")[0]; x.appendchild(newel); } </script> </head> <body> <div id="main1"> <input type="button" onclick="addselectbox ()" name="clickme" value="+"/> <input type="button" onclick="removeselect();" value="-"/> <input type="button" onclick="xmldata();" value="xml" /> </div> <div id="main"> </div> </body> </html>
it great if me in running this.
pick option in js fiddle menu doesn't wrap code in onload or onready function.
wrapping function declaration in function cause locally scoped, won't able access global through intrinsic event attribute onclick
.
better yet, stop using globals , intrinsic event handler attributes , bind event handlers unobtrusively javascript.
Comments
Post a Comment