Recursive Function Is (possibly) Writing Over Array?
Sep 16, 2010Here's a simplified version of the function that's giving me trouble:
Code:
function saveArray(w){
var arr="['z',[";
[code]....
Here's a simplified version of the function that's giving me trouble:
Code:
function saveArray(w){
var arr="['z',[";
[code]....
I'm trying to return all the permutations of a given string, so I wrote the following recursive function:
The problem is, I'm not getting all the permutations, and I don't know why.
For example, if string="bindle", the output I get is:
And then the function stops.
I'm having trouble with a recursive function.
The function is supposed to identify nested folders in a hierarchical
folder structure.
The function "searchForFolders()" is supposed to traverse sibling
nodes in each iteration, and for each sibling node, it calls itself
again, to see if there are child nodes of the current sibling.
The code below contains the function in question. For simplicity's
sake, I have replaced the images with text characters. It doesn't
look as good, but you should be able to see how the nesting works.
When you click on a "Folder", you will get debug text on the RHS of
the screen.
You will see there is an XML hierarchy. That is parsed by another
function in the page to write out the hierarchy. That is working
fine. The only functions that I am having trouble with are
"searchForFolders()" and "hideShowFolder()". Code:
I'm calling a recursive function, and I want to display an alert after its done running, the thing the function is "done" after goes through it once.Here's the coles notes version....
Code:
function yay(n){
n = n-1;
if(n=0){
[code]....
I don't want it to show the alert until its done all of it's recursive splendor.
I am coding an AJAX DHTML whatever application and I was fed up with
always typing a lot of appendChild() functions.
I created a custom one called append_children() and wanted to share it
if anyone need such a function.
function append_children() {
var a = append_children.arguments;
for ( var i = a.length - 1; i > 0 ; i-- ) {
try {
a[i-1].appendChild(a[i]);
} catch(e) {
for ( var j = 0; j < a[i].length; j++ ) {
append_children(a[i-1], a[i][j]);
}}}}
Here's the function:
function getParentElementByTagName(child, TagName){
var cn;
if (child.parentElement){
cn = child.parentElement;
if (child.parentElement.tagName == TagName){
return cn;
}else{
getParentElementByTagName(child.parentElement, TagName);
}}}
although it finds the element, the function returns null ( on the line
'return cn', cn is not null though). Is my algorithm wrong ?
I have written a function that works but it is recursive so ends up blowing the browser stack.I have seen a few examples of converting recursive functions to use a local stack but cannot convert my own function.I have a recursive function that is using the return values to build a result.
View 2 Replies View RelatedI've got following function:
[Code]....
I would like to run this in recursive mode, and I'm starting the function with:
$(function(){
$.bubbles();
}
The problem is, that function works only one (and a half) time. Console shows: start callback start I have not idea what is a problem. Function needs to be run constantly.
I have seen many script and pages on the Net, that show a code like this as correct
[Code]...
but when I try I receive the error countDown is not defined.
I have been looking at this code for two evenings now, and rewrote it 4 times already. It started out as jQuery code and now it's just concatenating strings together.
What I'm trying to do: Build a menu/outline using unordered lists from a multidimensional array.
What is happening: Inside the buildMenuHTML function, if I call buildMenuHTML, the for loop only happens once (i.e. only for 'i' having a value of '0'.) If I comment out the call to itself, it goes through the for loop all 3 times, but obviously the submenus are not created.
Here is the test object:
test = [
{
"name" : "Menu 1",
"url" : "menu1.html",
"submenu" : [
[Code].....
'Menu 2' and 'Menu 3' don't show up! I'm sure it's something small that I'm overlooking.
I am "writing" a javascript function to my page with php:
<html>
<head>
<title>Just about everything</title>
[code]....
I'm not that familiar with javascript, and I am trying to write a
toFixed function.
The function takes two arguments, the number and the number of decimal
places we're interested in.
If the number of decimal places is negative, it's interpreted as the
number of significant digits.
Thus:
toFix(12345.6789,2) -12345.67
toFix(12345.6789,0) -12345
toFix(12345.6789,-2) -12000
I've hacked up a solution that so far works on all tested browsers for
the first 2 cases.
It's the last one I'm having trouble with... How do I get only the
significant digits?
It has to work for all of the following cases:
toFix(12345.6789,-2) -12000
toFix(12345.6789,-5) -12345
toFix(12345.6789,-7) -12345.67
I'm sure a Google search could answer this, but I don't know what it's called, haha. Dot sytax maybe?chain methodsHow do I write a function that can be called like this:
$('p').myFunction().val('the new value');
I played around, tried this:
function myFunction() {
$(this).css({'color': 'red'});
}
[code]....
I've got a glitch somewhere and it's not obvious to me. Maybe someone can spot it.My problem is that the functions seem to return values but don't display them like they should. I'm testing returned values with a function called sayvalue(item). But when I test "DelTimeCode" the function returns "[Object]". I don't understand. I get returned values from DelTime and DelTitle.My approach is to select a radio button option, return a delivery title and a delivery price from the appropriate functions then write the information. I think I'm close. Any suggestions or observations of an error in my code?I have the following VARIABLES and FUNCTIONS:
<head>
var AmtSV;
var DelTimeCode="";
[code]....
I want to use HTML5's audio coding similar to the one below:
In order to play sound files depending on the input. What I'm working on is a text-to-speech webapplication.
What I'd need to happen is for there to be an input and then allow the user to type anything into the input, so if they type in:
Hello, how are you doing?
Javascript or PHP will recognize each character and translate it into an audio sequence.
In example:
It'd detect the "H" in hello and play sound file "H.ogg"
It'd then detect the "E" in hello and play sound file "E.ogg"
I've been using the document.write function to loop through some xml and print the data within a HTMl table. I thought it would be useful to add a hyperlink to the table row, so I thought the best way to do this would to create a function (called popup), which takes an id as a parameter.
The problem with this, is that when writeing using the onClick, the speech marks seem to all get messed up.
Code:
onclick='popup('"+mailID+"')'
I'm 99% sure it's just the speech marks, i'm just not sure of the right combination, and it's doing my head in
If someone could even point me in the right direction, even the proper name as to what this is called would be great, as googleing it is proving to be a nightmare!
Here's the whole section of code if it's more useful:
Code:
var mailID = x[i].getElementsByTagName("mailid")[0].childNodes[0].nodeValue;
if (r == "unread") { //email is unread
document.write("<tr onclick='popup('"+mailID+"')' title='test'>"); } else { //else is read, so add colour
[Code]....
What is the purpose of writing a function inside parentheses?
PHP Code:
(function()
{
var myvar = xxx;
// my function code here....
}
)()
If you specify arguments when writing a function should you still declare the argument variable inside the function?
example:
Code:
or
Code:
For example I have a link that I want to when I click on it, It writes some words after the link. I have written a code but it does not work as I want and it clears all the page and writes the words. I don't want to clear the page and write just words, I want to add words after the link.
Here is my code:
HTML Code:
<script type="text/javascript">
function a() {document.writeln('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');}
</script>
<a name="aaa" href="javascript:void()" onclick="a()">Click on me!</a>
Is there a way to write a custom tweening function, preferably with easing, without the use of the build in animate() function?In Javascript, it's possible to do this with an interval, but I haven't been successful in finding something similar for jquery
View 1 Replies View RelatedHow would you go about writing a function that returns a string that outputs a branched bulleted list using <ul> and <li> tags of all the html elements in a page? The html elements don't all have id's or names, so I cannot reference them directly. I would like to do it recursively so that I can grab all the elements, not just those two or three levels deep.
[Code]...
Does anyone have any recommendations/experience for loading a styled panel on the page (possibly based on a timer)? Do you know when you're on a site and a window pops up asking if you need help or want to chat... that's what I'm looking to accomplish. Something more than just text... I want a fully styled panel.
View 1 Replies View RelatedI have a website that I'm trying to install a shopping cart on and I'm trying to make it so when a certain color is selected an option pops up as an additional feature people have the option of choosing, but I only want the option visible when certain colors are selected. I think I have the code figured out, but there are 2 colors I want the option visible for and currently the option is only showing up for one of the colors. I tried creating two id's for each color and two jQuery codes that were basically the same but one for #color1 and one for #color2 but that didn't work either.
jscript:
css code:
I have a form which calculates values and gives the user a total depending on their selection in the drop down box. At the moment the value is displayed in a text field and I have got all the javascript to do this.
What I would ideally want is to embed the total in the page, rather than a text field. The total appears to the user like it is normal text in a page, only it will update when the form values are changed.
I presume that I want document.write to do this? Does anyone know how I could do this/ or if there is a page that does this sort of thing where i can 'borrow' the code?
I've not been doing javascript too long and it's my first forray into AJAX so maybe a glaring error.
I'm writing and approve/delete function for a website's pending memberslist in my approveMe script firebug says doWork is not defined.
I am trying to understand somecode. I don't think I am understanding everything correctly. Can someone confirm or add to my understanding?
Here is the code, below is my explanation:
- CODE 1 - is saying if the the class subnav_dd is called on an anchor tag on a li, then make the function in the if statement "live". (Live in a sense binds the function to the condition, but unlike bind it allows the condition to be used more then once. ) So if the class subnav_dd is the parent, and has a class of .dis then prevent anything below it from firing. CSS - If code 1 is true, then I will only get the first li to fire, the remaining ones will not.
- CODE 2 - This one is a little tricky. Function ToggleOptions takes 3 variables (target, array, state). The condition is if the div subnav + target have siblings, then check to see how many siblings are there. Put the amount of siblings into an array, then check the state of each sibling. I don't completely the rest of it.
I think if the div subnav is called and something is found in the array then the class dis is either added or removed. Then what? I don't understand why I still need the else that adds a class to #subnav_ +.target