JavaScript - How Do I Use Recursion To Get A Family Tree
Hello
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... Any suggestions to put me on the right line would be greatly appreciated Thanks Similar TutorialsOn my webpage, I dynamically create an iFrame when a button is pressed, then load a html page from within my own domain into the iframe, based on what html page is loaded into a variable. My question is, can I dynamically change the font family of the loaded html page from the javascript of the main page? My code to create the iframe is: Code: function setSubTxt(){ var par = document.getElementById('parentDiv'); par.innerHTML = '<iframe src="'+subTxt+'" style="width: 375px; position: fixed; height: 365px; left: 400px; top: 145px; border=none;" name="subIframe" frameBorder=0></iframe>'; frames['subIframe'].window.location=subTxt; document.subIframe.document.body.style.fontFamily = "Arial"; $('parentDiv').fade(1); } the variable "subTxt" has the url of the html page to be loaded (always on the same domain). The code: Code: document.subIframe.document.body.style.fontFamily = "Arial"; was my attempt to dynamically change the font, but it didn't work. Also, it should be noted that there is no font family set in the html pages which would override this. Thanks hello every one , i'm new and i hoped u could help me with my code I keep getting the same message "too much recursion" and i really don't know what is wrong , my friend and i codded the same way ,but it works for her not for me , here is the code : [merge sort algorithm] Code: var A=[2,999,45,23,17,879]; var B=[]; var C=[]; var i; var j; var k; var x=0; var mergesort_counter=0; var merge_counter=0; mergesort(A); //========================================================= //document.write( "<h2>mergesort</h2><p>", A, "</p>" ); function mergesort(A){ var n=A.length; mergesort_counter++; //count mergesort calls document.write( "<h2>mergesort</h2><p>", A, "</p>" ); var mid=Math.floor(n/2); if (n>1){ for (i=0;i<mid;i++){ B[i]=A[i];} for(j=mid;j<n;j++){ C[x]=A[j]; x++;} mergesort(B); mergesort(C); merge(B,C,A);} else document.write("the list is too short ");} function merge(B,C,A){ merge_counter++; //count merge calls i=0;k=0;j=0; while( i<B.length && j<C.length ){ if (B[i]<=C[j]){ A[k]=B[i]; i++;} else{ A[k]=C[j]; j++;}k++;} if(i==B.length) for (var l=j; l<C.length ; l++) {A[k]=C[l]; k++;} else for (var l=i; l<B.length ; l++) {A[k]=B[l]; k++;} document.write( "<h3>merge</h3><p>", A, "</p>" )} this code: Code: $(document).ready(function() { $('body').click(function(evt) { if(evt.target.nodeName === 'A' && $(evt.target).hasClass('cross-link')) { $('a[href=#2]').trigger('click'); } });}); gives me and error of "too much recursion" how can i solve this? Code: function checkifischild(draggedElement,destination) { $getid = $("#" + destination).attr("class"); var __temp = $getid.split(' '); console.log(__temp) for(i = 0;i < __temp.length; i++){//for the length of the classes if(__temp[i].match("child-of-")) {//check if its a child parent = __temp[i].substring(9);//get the parents node if(draggedElement == parent) { console.log('yes'); return false; } } } checkifischild(draggedElement,parent) } i have the following function basically what it does it gets 2 parameters node-23,node-17 for example it finds the classes of node-17 and splits them up ["child-of-node-16", "initialized", "ui-droppable", "expanded"] ["child-of-node-19", "initialized", "parent", "expanded", "ui-droppable"] ["child-of-node-23", "initialized", "parent", "expanded", "ui-droppable"] so i compare each time the first parameter along with the substring of the child-of and if they are the same its returns false now my problem is if i call the function just like this checkifischild(node-23,node-17) it works i get in the console yes for example if i do this tho if(checkifischild(node-23,node-17) == false) it fails :? any ideas will be appreciated thxxx Hey im having a problem recursively calling my function. What I want to do is to change MyImages[0-14] with a timeout between them. Here is my code. Code: function swapImage(i) { if(i < 15) { MyImages[i].src = "red_dot.gif"; setTimeout("swapImage(i+1)",500); } } The problem is that it will only change MyImages[0] and MyImages[1] Hi, can anyone tell me... Code: function Obj() { this.recursiveMethod=function () { //...how to invoke Obj.recursiveMethod from here? } } Gus Well, I clearly haven't the experience with javascript to understand why I can't do this: Code: function bubbleSortKernel(a, b) { if (b < 50) { swap(a, b); draw(); setTimeout("bubbleSortKernel(++a, ++b)", 200); } } where Code: swap(a, b) does just what it says: swaps the two elements in an array, and Code: draw() looks about like this: Code: function draw() { if (ctx != null) { ctx.clearRect(0, 0, width, height); for (var i = 0; i < rectangles.length; i++) { ctx.fillRect(x, rectangles[i][0], rectangles[i][1], rectangles[i][2]); } } } I'm newer to javascript that other things, and this seems perfectly legal to me. I'm looking for someone who knows more that I and can explain what I'm missing. I'm guessing my timeout doesn't really work like I think it does, but I've gotten so frustrated I can't see the forest for the trees. Any help or nudge is greatly appreciated. Thanks! Hi, I am having trouble with a recursive function I created to list out the indexes and values of various nested objects. Code: 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: Code: 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("\n"); } } printObj(macros); The current output: Code: 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> Any advice would be appreciated. Cheers, Gus well, when i do this fucntion: function scroll(){ window.scroll(0,60) } i get a javascript error: Error: too much recursion well, what is wrong? what does that mean? how do i fix it? thanks for any help Hi, need help in making a check box list menu, wherein when initial check box is clicked another checkbox will appear. Help Help Hi all, I'm looking to find a way to making a FAQ selection search which has a hierarchy effect. For example: Whats your favorite color? Red Blue Green Say you select red What shade of red do you prefer? Dark Light Say you select Light Final page that will contain the information that you had rounded down through the search. Does any one have any ideas on how I can do this as I cant seem to find anything on the net! Thanks Hi, I am really in a slump right now... I thank all of the people who have helped me in this site... i have a script already that allows check boxes to show the next checkbox using the onclick function. and now I cannot figure out how to make a decision tree.. eg. a person will call or ask for 4 possible inquiries.. billing leads to 2 scenarios - the caller wants the charges explained; once explained its good - the caller wants the charges cancelled technical leads to 2 scenarios -the caller asks for technical assistance; hence resolved -the L1 tech cannot resolve the problem and escalates it to a higher dept gen inq leads 3 scenarios - sell the product - higher department cannot locate any account - declines the sale cancellation leads to 2 scenarios - with refund - no refund i am thinking of a combo box for this to make things much easier.. but it is not.. the hard part for me is when the last check box is clicked I want this drop down shown then, after the user selects the any of the scenarios another check box appears and then another one to finish the process. also I had a script were in all the selected values can be copied to a clipboard but, doesnt copy it. I am really really depressed about this.. I want to learn the js. but I am stuck with the level 0 degree.. please help me.. Hi all. I'm experiencing an issue with dijit.Tree/ForestStoreModel/ItemFileWriteStore and I just can't seem to figure out what's going on. If I start with an empty store model ... var myData= { "identifier" : "id", "label" : "name", "items" : [] }; var myStore = new dojo.data.ItemFileWriteStore({ data: myData }); var myModel = new dijit.tree.ForestStoreModel({ sto masterStore, query: {type: 'task'}, rootId: "tasks_id", rootLabel : "Tasks", childrenAttrs: ["children"] }); If I eventually execute newItem on the store, the tree is not updated. myStore.newItem( { id: "2", name : "someName2", type : 'task', children : [], } ); However, if during declaration of my data, I include 1 item, ie. var myData= { "identifier" : "id", "label" : "name", "items" : [ {"id" : "1", "name" : "someName", "type" : "task"} ] }; Then I can subsequent call newItem as many times as I wish, and the tree is updated correctly. If anybody has any ideas, I'm all eyes. I would like to put a script on our website that users could interact with and that would ask a series of questions and based on those questions propose answers. Im surprised I cant find much on the web to help me do this. Does anyone know a PHP script, widget, or template that could provide me this functionality? I just want to be able to input a series of questions and answers and the logical flow and be able to host it on our web server. I need to render a tree in freemarker. I am not sure about what technology should be used. I was thinking Jquerys jsTree plugin. My requirements - 1. Tree control -Name and instead of Icon ,i want customized letters(A,B,C) that represents type of element. 2.I dont want dotted lines connecting root and children like folder tree. 3.collapsable. Please suggest what and how can i do .? woundering if any could point me in the right direction, where i can find a soul tree canculator script or any one who can make one. thanks shaun. Code: <script type="text/javascript"> function validate(form) { // Checking if at least one period button is selected. Or not. if (!document.form1.sex[0].checked && !document.form1.sex[1].checked){ alert("Please Select Sex"); return false;} var total="" for(var i=0; i < document.form1.scripts.length; i++){ if(document.form1.scripts[i].checked) total +=document.form1.scripts[i].value + "\n" } if(total=="") alert("select scripts") else alert (total) return false; } </script> <table border='0' width='50%' cellspacing='0' cellpadding='0' ><form name=form1 method=post action=action_page.php onsubmit='return validate(this)'><input type=hidden name=todo value=post> <tr bgcolor='#ffffff'><td align=center ><font face='verdana' size='2'><b>Sex</b><input type=radio name=sex value='male'>Male </font><input type=radio name=sex value='female'><font face='verdana' size='2'>Female</font></td></tr> <tr><td align=center bgcolor='#f1f1f1'><font face='verdana' size='2'><b>Scripts You know</b><input type=checkbox name=scripts value='JavaScript'>JavaScript <input type=checkbox name=scripts value='PHP'>PHP <input type=checkbox name=scripts value='HTML'>HTML </td></tr> <tr bgcolor='#ffffff'><td align=center ><input type=submit value=Submit> <input type=reset value=Reset></td></tr> </table></form> In this code a checkbox is accessed as "document.form1.scripts[i].checked" If we see the tree view of this document, it is "table/form1/tr/td/scripts[i].checked" SO are we not required to add table elements in the path to the checkbox ? I guess its not required. But why ? Because cell, row and table are the parent elements in HTML tree, then why are they not required ? Code: oaktree.addItem("RC Mail", branch1, "rcmail/") //Add this item to branch2 I can open it up in the current page, but the menu is in a frame and I need to open it in a fram called "home". How can I do that~?? Hello, I have a specific need in javascript. Can I be guided in this context if its possible or not??? I am using virtuemart extension in joomla to make an ecommerce website. I will try to explain my requirement with the example. Following is the sample category tree with number. 1.0 .....1.1 ..........1.1.1 ..........1.1.2 .....1.2 ..........1.2.1 ..........1.2.2 .....1.3 ..........1.3.1 ..........1.3.2 2.0 .....2.1 ..........2.1.1 ..........2.1.2 .....2.2 ..........2.2.1 ..........2.2.2 .....2.3 ..........2.3.1 ..........2.3.2 Now I have a drop down main menu as 1.0 and 2.0. I want that when i click on 1.0 all the nodes of 1.0 should be opened and 2.0 should be closed and similarly when i click on 2.0 all its child nodes should be opened and 1.0 should be closed. What happen with most extensions is that at a time only one child is opened. If i click on 1.0 then only 1.1 or 1.2 or 1.3 will remain open at a time. Does this kind of customization can be done or is available in javascript .... I hope i will be helped... Thanks a lot for the time. |