SugarGirl
02-11-2003, 11:23 AM
Is there a way to display something that is in my .js library file on my webpage??
|
Click to See Complete Forum and Search --> : Displaying from .js library to html SugarGirl 02-11-2003, 11:23 AM Is there a way to display something that is in my .js library file on my webpage?? pyro 02-11-2003, 11:29 AM ...huh? :confused: AdamBrill 02-11-2003, 11:50 AM There isn't any way of doing that in javascript. You would have to do it with PHP or some other server-side language. If you need help, I could write you a simple PHP to write out the contents of a .js file. SugarGirl 02-11-2003, 11:51 AM What I am trying to do is debug my code, and what I wanted to do is at certain points in my .js library files I would like to print something like "Got to here" so I know where the code executed to and I would like to print out my array contents to see why I am not getting the result I want. SugarGirl 02-11-2003, 11:56 AM The problem is that I am editing a .js library file that contains a bunch of arrays and at certain points I would like to print out the array contents to my webpage so that I can figure out what array I am working with (I am dealing with 6 menus all 2 sublevels each so there is a couple arrays) Jona 02-11-2003, 11:59 AM You can't write to a file using JavaScript, but you can include the .js file and document.write() it to the page.. <SCRIPT SRC="includes/file.js">document.write(theArrayName)</SCRIPT> AdamBrill 02-11-2003, 12:08 PM The way that seems to work best for me is putting alerts in there. You can put them in, have them display the contents of the array, and then you will know if the code is getting that far or not. Then you just have to remember to delete them after it is working! ;) SugarGirl 02-11-2003, 12:13 PM How would I create an alert??? Jona 02-11-2003, 12:17 PM Same way as document.write: <SCRIPT SRC="myscript.js">alert(yourArrayName)</SCRIPT> or... you can change your code so that when the Array is called, it alerts telling you the array with... alert(youArraysName) AdamBrill 02-11-2003, 12:32 PM Actually, what I would do is go into the .js file and put an alert in there. Like this: alert(arrayname); You can put it in there and then check if it is making in that far. If everything looks right, you know that the problem is below the alert. If it doesn't work, then the problem is above the alert. You can move it around and find out exactly where the problem is happening. I hope that helps... What is your code supposed to do? If you want, you could post it and I'll take a look... SugarGirl 02-11-2003, 12:34 PM Here is my function that I am trying to figure out what is in the array. This is a multilevel array and I would like to see how the data is organized, how many arrays what is in each array, by printing the array data to my webpage. Possible??? ///////////////////////// //// transforms raw text input into a multilevel array //// returns an array based on the string input function _compile(ary,str){ while(1){ // keep circling and eating the str // when the str is empty, return the built array if(str.length == 0){ return ary; } // is there any more sub-arrays? var nextA = str.indexOf("["); if(nextA == -1){ var go = str; var spawn = ""; str = ""; }else{ var go = str.substring(0,nextA); var spawn = str.substring(str.indexOf("[") + 1,_pair(str.indexOf("["),str)) str = str.substring(_pair(str.indexOf("["),str) + 1,str.length); } // build a flat array of key/value pairs and strip out the empty elements var A = go.split(";"); var A2 = new Array(); for(var j=0;j<A.length;j++){ if(A[j].indexOf("!") != -1){ A2[A2.length] = A[j]; } } A = A2; // parse the flat array for(var i = 0;i < A.length;i++){ var tmpA = A[i].split("!"); var thisary = ary.length; ary[thisary] = new Array(); // attach a sub array if needed if((i+1)==A.length && spawn.length != ""){ ary[thisary] = _compile(ary[thisary],spawn); } // assign properties to this array based on the parsed array key/value pairs ary[thisary].name = tmpA[0]; ary[thisary].url = tmpA[1]; ary[thisary].desc = tmpA[2]; ary[thisary].icon = tmpA[3]; } } } /////////////////////// Jona 02-11-2003, 12:40 PM if(str.length == 0){ alert(ary); return ary; } var go = str.substring(0,nextA); var spawn = str.substring(str.indexOf("[") + 1,_pair(str.indexOf("["),str)) str = str.substring(_pair(str.indexOf("["),str) + 1,str.length); alert(str) } var A = go.split(";"); var A2 = new Array(); for(var j=0;j<A.length;j++){ if(A[j].indexOf("!") != -1){ A2[A2.length] = A[j]; } } A = A2; alert(A); alert(A2); // parse the flat array for(var i = 0;i < A.length;i++){ var tmpA = A[i].split("!"); var thisary = ary.length; ary[thisary] = new Array(); alert(ary[thisary]); alert(ary); // attach a sub array if needed if((i+1)==A.length && spawn.length != ""){ ary[thisary] = _compile(ary[thisary],spawn); } alert(ary[thisary]); alert(ary) And if you want to write that to a page, you change all of the alerts to, "document.write()"s. Be sure to add the semi-colon at the end of each document.write();. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |