Using Recursion To Print Out Nested Objects
Dec 29, 2009
I am having trouble with a recursive function I created to list out the indexes and values of various nested objects.
var macros={
CTRL: {
ALT: {
ENTER: "<br />",
P: "<p>.</p>",
A: "<a href="">.</a>",
_1: "<h1>.</h1>",
_2: "<h2>.</h2>",
_3: "<h3>.</h3>",
_4: "<h4>.</h4>",
_5: "<h5>.</h5>",
_6: "<h6>.</h6>"
}}};
I want to print out the whole 'bread crumb trail' to each object, ie CTRL ALT 6: <h6>.</h6>, but at the moment my function prints out CTRL ALT twice for 'ENTER' and then never again. The function:
function printObj(obj) {
for(i in obj) {
var n=i.replace("_", "");
document.write(n);
if(typeof obj[i]=="string") {
document.write(":");
document.write(" "+obj[i].replace(/</g, "<").replace(/>/g, ">"));
} else {
document.write(n);
}
if(typeof obj[i]=="object") printObj(obj[i]);
document.write("
");
}}
printObj(macros);
The current output:
CTRLCTRLALTALTENTER: <br /> P: <p>.</p> A: <a href="">.</a> 1: <h1>.</h1> 2: <h2>.</h2> 3: <h3>.</h3> 4: <h4>.</h4> 5: <h5>.</h5> 6: <h6>.</h6>
View 4 Replies
ADVERTISEMENT
Aug 24, 2010
I have multiple divs something like this
<div id="div1">
<div id="div2">
<div id="div3">
[code]...
I want JavaScript code to print div1 with all nested divs as well I tried using the following code but it only print div1 content
PHP Code:
var printContent = document.getElementById('div1');
var windowUrl = 'about:blank';
var uniqueName = new Date();
[code]...
View 1 Replies
View Related
Mar 31, 2006
I'm writing examples for placing standards-compliant java applets in XHTML or HTML documents. And I'm also testing with Javascript. At some point, I created two 'object' elements, each with their 'param' children. Code:
View 6 Replies
View Related
Aug 25, 2010
I have multiple divs something like this
<div id="div1">
<div id="div2">
<div id="div3">
[code]....
I want JavaScript code to print div1 with all nested divs as well I tried using the following code but it only print div1 content
var printContent = document.getElementById('div1');
var windowUrl = 'about:blank';
var uniqueName = new Date();
[code]...
View 5 Replies
View Related
Nov 17, 2009
I posted this once, but it disappeared, and I have no notifications that I did anything wrong. I read the rules before posting and wasn't breaking any so I am not sure why it disappeared but here goes again.
I am trying to learn Javascript (particularly OOP) from a series of screencasts by Douglas Crockford. I have developed a theoretical "game" to build to illustrate it to myself better, and learn by example.
I must be misunderstanding how inheritance works, because my code is not producing the results I thought it would. Here is what I have, followed by an explanation of my understanding. $(function()
[Code]...
View 11 Replies
View Related
Apr 29, 2011
I'm trying to reuse some code in a different context to do a different job.The code to be reused contains hundreds of lines similar to a = new b.c.d(e,f) with different value for e and f.I need to create a new user defined object with the structure b.c.d. I've made numerous attempts along the lines of:
function d (e, f) {
this.e = e;
this.f = f;
}
[code]....
with various permuations of functional declarations.However I get error message "Object expected" or "b.c.d is null or not an object" at the final line of the example.It works with the test line var a = new d("test", "message") but not when I start to build up the expression.How should I define of b.c.d?
View 8 Replies
View Related
Aug 9, 2011
I have the following object:
var wDefaults = {
"skin":1,
"pagewidth":"960px",
"c1col":[
{"wid":"w001","pcol":0,"wpos":0,"wclosed":"false","wcollapsed":"true"}
],
"c3col":[
{"wid":"w002","pcol":0,"wpos":0,"wclosed":"false","wcollapsed":"false"},
{"wid":"w003","pcol":0,"wpos":1,"wclosed":"false","wcollapsed":"false"},
{"wid":"w004","pcol":0,"wpos":2,"wclosed":"false","wcollapsed":"false"},
{"wid":"w005","pcol":1,"wpos":0,"wclosed":"false","wcollapsed":"false"},
{"wid":"w006","pcol":1,"wpos":1,"wclosed":"false","wcollapsed":"false"},
{"wid":"w007","pcol":1,"wpos":2,"wclosed":"false","wcollapsed":"false"},
{"wid":"w008","pcol":1,"wpos":3,"wclosed":"false","wcollapsed":"false"},
{"wid":"w009","pcol":2,"wpos":0,"wclosed":"false","wcollapsed":"false"},
{"wid":"w010","pcol":2,"wpos":1,"wclosed":"false","wcollapsed":"false"}, {"wid":"w011","pcol":2,"wpos":2,"wclosed":"false","wcollapsed":"false"}
]}
First, how do I access a single value? I've tried some of the examples I saw on the forum, but nothing happened. The alert did not fire:
alert(wDefaults.c3col[0].wid); //first try
alert(wDefaults.c3col.0.wid); //second try
var obj = wDefaults.c3col[0]; //third try
alert(obj.wid);
The nested objects are the properties for widgets within a portal. After the user moves around the widgets, I need to update the object, putting the widgets in a different order within c3col and updating the values saved in pcol, wpos, wclosed, & wcollapsed. I also may need to add or delete an object, for example, delete wid=w003 and add a new one called w012.
My logic would be:
for each widget on the page
found = false
find the object in c3col where wid == x and update its other values
. set found = true
if found == false then add a new object to c3col with x & its properties
end for
for each object in c3col
if that wid isn't found in the list of widgets on the page, delete it from c3col
end for
sort the objects under c3col by pcol and then wpos
The red parts are the ones I'm unclear about how to do it. My basic questions are:
(1) How do you access a single nested object?
(an object within c3col, find and change its values)
(2) How do you add a new nested object to an existing object?
(add a new object to c3col)
(3) How do you delete an nested object?
(remove an object from c3col)
(4) How do you sort nested objects?
(sort the objects in c3col by pcol and wpos)
View 3 Replies
View Related
Aug 1, 2007
I am trying to program a script that will output the solution for the towers of hanoi problem, the only problem is that it will not output the solution it just hangs while calculating. Code:
View 2 Replies
View Related
Jul 3, 2007
I would like to print a Web page with javascript method window.print() without pages number and footer.
View 7 Replies
View Related
Aug 30, 2011
Can I configure this function to make it print a certain pixel only?
Around 500px X 700px Center.
CODE:
Is it possible?
View 1 Replies
View Related
Oct 27, 2011
wanna know how we can get the animation effect using the recursion method. following is the code:
$(document).ready(function(){
$(".flip").click(function(){
$(".panel").slideToggle(2000); // i wanna call this jquery animation recursively
[code]....
View 1 Replies
View Related
Dec 9, 2011
I am trying to create a family tree, parents / grandparents etc, of a single person... My database etc is already working but I cannot find any working examples that I can make sense of... Each of my records has a name, dob and id of each parent.... How can I get X generations from this.. I thought something like this might work.. GetParents For each parent GetParents And so on... But I have no idea how to put this into code...
View 2 Replies
View Related
Jul 20, 2009
I am having a problem finding the syntax for recursively adding images to a webpage using javascript. I have some pseudo code but no js.
already in a folder function 1 for each file in folder add file to webpage next folder function2 function2 for each folder within folder call function 1
I know the code isn't all that clear, but that's the best way I can describe it.
View 3 Replies
View Related
Apr 7, 2006
I'm trying to create a print link that sends the page to the printer without opening the print dialog box on the browser.
I know that window.print() will open the print dialog and then the user has to click OK.
is there anything that can do this?
View 1 Replies
View Related
Jul 21, 2009
I'm facing a different problem.
I'm having a long page where there will be content to be printed.
I'm using the css using media=print to hide all the unwanted contents and using the window.print method to invoke printing.
But when i click the print button it prints only partial content upto a single page and all the remaining contents are discarded.
I wonder what may be the problem!!!
And there's another problem , i've bills to be printed in order but dont want them to be breaking in between pages .(ie a bill should be printed fully if there is enough space at the bottom or should be printed on the next page)
How can i do both of this?
View 3 Replies
View Related
Jan 3, 2002
Hey all. I am currently putting together a test page of mine where a popup window comes up showing a coupon that I will have a link enabling them to print it simply and easily.
For my current code I have a simple <a href="javascript:window.print()"> that works great on both Internet Explorer 5 and Netscape 4/6 on the PC but for some reason, Internet Explorer 5 for Macintosh doesn't do a thing.
View 2 Replies
View Related
Oct 8, 2007
I am using the module pattern and private/public methods. I'm having a problem where the private method is using setTimeout() to call itself recursively, but I can't get the syntax right. Code:
View 1 Replies
View Related
Apr 29, 2006
I have this script. It's supposed to give the Fibonacci numbers but the recursion won't work. It just prints out 1 number that the user entered and that's it. In IE6 it prints 1 number but in Firefox it prints the same number an infinite number of times. Whats going on? Here is the script:
<html>
<head>
<script language = "javascript">
function fib(form)
{
var fibVar = Number(document.myform.inputbox.value);
document.write(fibVar);
if(fibVar == 0 || fibVar == 1)
return fibVar;
else return fib(fibVar - 1) + fib(fibVar - 2);
}
</script>
</head>
<body>
<form name="myform" action="" method="get">
<input type="text" name="inputbox"><br>
<input type="button" name="button1" value="Calculate"
</form>
</body>
</html>
View 1 Replies
View Related
Apr 17, 2011
Is there a way in Javascript or Jquery to return an array of all objects underneath a certain point, ie. the mouse position. Basically, I have a series of images which link to various web pages but I have a large semi transparent image positioned over the top of the other images. I want to find the href of the background image that the mouse pointer clicks over.
View 1 Replies
View Related
Mar 20, 2011
Firebug returns an error and I like to ask you how I could improve my code.
[Code]...
View 3 Replies
View Related
Apr 24, 2009
I would like to know if there is a simple way to show all elements of that variable?
var collectionElements = {
teste: {
var1: 'teste[]',
[Code].....
With this function my firebug Console outputs only the last object(3th node) with its child object.
View 1 Replies
View Related
Jul 20, 2005
Is it possible to do an ie print from javascript that does not bring
up the print dialog? I'm in a situation where i need to load a
sequence of files into a browser and print all of them without any
user interaction.
View 3 Replies
View Related
May 1, 2009
Is there a way to get a print preview triggered by a button rather than just print?
<input type="button" name="print" value="Print" onClick="document.print();">
Unfortunately, the WebBrowser.execWB(7) functionality doesn't work in FF3.
Any idea using good old fashion JavaScript or jQuery?
View 1 Replies
View Related
Jun 22, 2007
So I have a print page that's written in a combination of php & html. The body tag is outside the php with an onload="window.print();window.close;"
The idea behind this print page is when the print button is pressed on the parent window, it generates this child window that is specifically made larger for printing reports that people can read easily. I use css for text styles and the table "width" is longer.
All the html code inbetween the body tags is created by php using the php "Print" function.
</head>
<body class="page" onload="window.print();window.close;">
<?php
Print "<table width=1600 border=1 cellpadding=0 cellspacing=0 class=page>";
Print "<tr bgcolor=cbe5ff>";
Print "<td width=30>WO #</td>";
// yada yada yada
?>
My problem is it does not print the table dimension or the font size above a certain size. When I print in landscape, which is what this page is designed for, it prints the same size as "scaled to fit" portrait. On the screen the size is correct and if I use the browser print button, it prints to the correct size.
The css works, it will make changes and will even make the text smaller just won't print over a certain size (9pt?).
View 1 Replies
View Related
Jun 27, 2007
I have a requirement to print particular area of a web page. Web page has many div's and one iframe in it. I need to print a div and iframe content with one single print command. I am able to do so but then two print dialog boxes come up when the print command is given. I have written a javascript function to achieve this.
I did find a solution to this but then I do not understand why onload fails to work in this scenario. I am summarizing steps I had followed.
1) Read the contents of div using innerHTML and store it to a variable.
2) Read the contents of iframe and store it to a variable. "Details" is id of the iframe.
var iframeObj = document.getElementById("Details");
var iframeDoc;
frameDoc = iframeObj.contentWindow.document;
3) Open a window and write all these content after writing these few lines
flashDivWindow.document.write('<html><head><title>Print page</title></head><body onload="javascript:window.print()">');
When I view the source all HTML code can be seen as expected, however this doesn't trigger onload event. I need to refresh the page for print to happen, some thing which isn't practical. Using Javascript reload doesn't help as print is invoked even before the page content is reloaded.
View 2 Replies
View Related
Sep 5, 2009
Is there a better way to extend object with internal objects?
$.fn.bestShow = function(s) {
var d = {
width: 0,
height: 0,
order: "numeric",
orderBy: "",
[Code]...
View 3 Replies
View Related