Can't Get Parallel Array To Work With BiggestValueIndex Function
Feb 20, 2009
After some earlier advice I have realised that I was trying to find the highest vale in an array not the index of that value. I have changed my code accordingly but I still have something wrong with it. It still returns undefined.
I need to have the function findHighValueIndex(anArray) as I will be adding more arrays later.
I'm using an array to store map features (name, lat, lon, caption, etc), from which the user can then select an individual feature. The problem is that when thousands of features are stored in the array, looping over the entire array looking for a match is SLOW.
So I'm running a hash in parallel, where every time a feature is pushed onto the array it's name is also added to the hash as an identical key value pair. I then check if the key is defined in the hash, and if it is, I want to use that feature's values from the array. Problem is, I don't know the index number in the array for this feature. Is there a way to look this up without looping over it, by matching values between the array and hash? Code:
I am working on a very simple code to determine the highest value from an array and also use parallel arrays.
The problem I am having is, when I try to invoke the parallel array namesArray it returns undefined.
I have coded the function so it can be used to find the highest value in more arrays as this is only the beginning of my code. Im not sure if this is what is causing the problems but I have a feeling it is code...
I have 4 arrays that all contain data linked by the index. I have 3 drop down boxes on a web page that give the user 3 ways to search for data. The top one is mandatory the other two are optional. I've managed to create the code to search using the mandatory box but cant figure out how to expand the search.
Here is the function that deals with the search data: function findFlights(){ var yourAirline = readTheAirline(); var result = 'Here are your flights <BR>'; var choose = 'Choose your destination';
for (var index = 0; index < flightTimes.length; index++){ var flight = flightDestinations[index]; var airline = flightOperators[index]; if (yourDestination == flight){ var b = flightTimes[index]; var c = flightDestinations[index]; var d = flightOperators[index]; var e = flightFares[index]; var message = b + ' to ' + c + ' operated by ' + d + '. £' + e + '.';
result = result + message + '<BR>'; }if (yourDestination == choose){ result = 'Please choose a destination city from the destination menu and then click Find flights again.'; }}displayMessage(result);}
I have been directed from .NET section to this section. My original post and question are here. forums.devshed.com/net-development-87/asp-net-how-to-send-data-to-parallel-port-600691.html
Is it possible to send data to parallel port using javascript?
What I have been given is two arrays and I need to multiply the elements in the first with the corresponding value in the second and then save the result into a third array. I have tried every option i can think of to do this, I entered the result values into the third array just to check the rest of my code is right
I have a function called 'loadScript' which is used to load JavaScript files in parallel (for the purpose of not blocking the browser from downloading other components at the same time).
See the following link for more information on the subject:[URL].. This function works fine for IE and Firefox and up until today has always worked for Chrome/Safari. But today I noticed an issue for WebKit rendering engines, which is that sometimes the callback method I pass to the loadScript doesn't always fire, only sometimes when I force refresh the page.
I'm trying to build a page that has multiple ajax calls on it. When you do it the old-fashioned way with XmlHttpRequest, you'd create a new xhr object for every call so that they execute simultaneously. If I try to do this in jquery it will only execute a call when the previous one has completed. This makes the page load time completely unacceptable. How to improve the performance?
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
I'm using the Google AJAX APIs, but some reason google.load works when run through normal javascript, but if I call the method from my jquery ready function it doesn't work. Code and output is below
window.loadFirebugConsole is not a function If I comment out line 3 in code.js, the console debug runs okay, so the ready function is running okay. Even though there's a reference to Firebug, the same error occurs in Safari too. Nothing on the page loads.
I'm looking for some guidance on a part of some coding practice I'm stuck on!
I've created a shopping cart using javascript, the items save to the arrays etc and it all works fine. If the user adds the same product again to the cart the quantity is added onto the previous quantity that is already in the cart.
To check if the item is already in the cart I've ued the below code, but what it does is update the quantity for the first cart, and when it updates the quantity for the second item it updates the quantity but keeps adding the same product to the cart in seperate elements of the array as well (if that makes sense?
here are the two functions used [code]...
It may jsut be a simple mistake I've made but it's been bugging me a lot and I can't seem to fix it.
See example at: [URL]. I want the thumbnails in 2 columns, not 1. Here is the javascript: Code: function ImgColumn() { var str = ''; for (var i=0; i<imgArray.length; i++) { str += '<div onMouseOver="Enlarge('+i+')">'; my_pic = 'mypic'+i; // my_src = imgArray[i][0];// not used here str += '<IMG id="'+my_pic+'" SRC="'+imgArray[i][0]+'" value="'+i+'"'; str += ' alt="'+imgArray[i][1]+'" BORDER="0" HEIGHT="70" WIDTH="70"><IMG SRC="images/spacer.gif" BORDER="0" HEIGHT="1" WIDTH="10"><br>'; str += '</div>'; } return str; }
And the HTML: Code: <table width="200" height="400" border="0" cellpadding="0" cellspacing="0"> <tr> <td><script type="text/javascript"> document.write(ImgColumn()); </script> </td> </tr> </table>
Am passing an array object back from ASP.NET but cannot work out how to access the child objects and get the value. Link is an image of the asp return object and what I am able view in javascript by console log of the data. Example image - [URL] been trying stuff like data.d.MessageText and a few others.
anotherVar should be -1 if there are no matches, but it doesn't seem to work var string = "abadafa"; var matches = string.match(/a/gi); //doesn't work with /z/ for example
var anotherVar = matches.length || -1; The default operator should return the second value if the first is null or false, and according to try { alert(matches.length);
The script works if the images are stored within the HTML but when I try to store them in the JS array, it fails. Is there any way to store the images in JS with this script?
I have small problem and I am stuck with it for days without any solution. So I have a function that has an array,
function arrjoin( ) { var a = new Array (1,1,1,1,1,1,0,0,0,0); var c = a.join("~"); return (c); }
I have another function that call the arrjoin(). But before doing so, I get a value from an input field based on which i need to update the array in arrjoin() and save that as the new array(I mean same array but with the update value).
[Code]....
This is my current function. In this before I call joinarr( ) I need to update the array a in joinarr( ) with the value=index, that I am fetching here and save the array. (Haven't implemented yet) This process keeps on occurring every time a index value is generated. Thus in the next iteration the array a in arrjoin( ) show not be array show here but the array with the updates values. I am eventually transferring the array to server side to do some processing based on current value of the array.
<script type="text/javascript"> function Toggler() { Alert();
[code]....
For some reason, this doesn't work on my page. onClick="Alert();" DOES work, but "Toggler();" doesn't. I know, right?! Further weirdness, the code DOES work if I create a simple HTML page that contains nothing but the code contained above. But when I put it into my existing page, it stops working whenever it's embedded. Alert works, Toggler doesn't.
My page is an index.php file which pulls a pre-established "head.tpl" and "foot.tpl", and slots in the requested content between them. I'm trying to put this code in "head.tpl". This is the only JavaScript I'm using (so far), and other than that it's all HTML, CSS and PHP.
I'm trying to pass titleArray and pointsArray to the task(); I'm getting an error mgs this.assignments() is not a function. I've highlighted this.assignments()
I am trying to put together a function that does the following; if a value is not in the array ..put it in, else if a value is already in the array...take it out. Something along the lines of the code below (but it doesn't work). Has anyone seen such a function or can see where I am going wrong? Code:
When using the following code, I press Sign Guestbook button and the alert does not show. The alert is there as a test to see if the function is being called.
The code below correctly formats a phone number in a form field. Works in fine in Safari, Chrome, Firefox, but not IE. Any ideas why or how I might correct it so that it works there as well?
I am loading a set of icons using an array. The reason for this is that the icon set will be different depending on what some PHP code has given to the JavaScript.
My code currently looks like this.
Code:
var things_to_load = new Array(); things_to_load['header_cursors'] = new Array( 'default' , 'pointer' ); things_to_load['header_icons'] = new Array( '../img/triggers/to-roll/undo.png' , '../img/triggers/add.png' ); things_to_load['header_labels'] = new Array( 'undo' , 'add' );
[Code].....
The problem I have is that the click function gives the error "things_to_load.header_clicks[c] is not a function".
This makes sense as presumably the click function is saving the value and not what that value references.
how I can get this code to save the function not the string referencing it?
Array.prototype.each = function (fn) { this.map(fn) }
This is my each function that works great in every other browser but IE. UGH! What am I doing wrong? the error points to the this in the function. Is it that IE doesn't like map? Has anyone seen this before? I thought my code was correct. Works perfect in FF, chrome and opera. the canvas text doesn't work in opera, but it does render the features so the each function is working.
I'll post the code if needed, but it's huge. here's the script running.[URL]..
im trying to take an array and create a new array in a function to have it be used in the calculation function. I keep getting undefined when trying to output it. I can pass it directly using Spec(skills, spec, train); inside the function but that defeats the purpose of the function since its not always going to be used.
ive looked for hours on google and its all just variables which i can work fine but for this it will not work.
function Aluvian(){ document.ACCalculator.skillcredits.value = 100; var skills = new Array(); var spec = new Array();
I would like to pass an array to a function but how does the program know which array I would like to choose from?? Lets say I have 3 arrays and I would like to pass array C, to my function. I checked the web but they only show if you have ONLY 1 array but NOT for multiple arrays. How would I even go about doing this??
function popsizes(colorcode) { var BLK=new Array(); BLK = ["2XL","3XL","4XL","5XL","LG","MD","SM","XL","XS"];
elem = document.getElementById("selcolor"); for (i=0; i<elem.options.length; i++){ sizelist = colorcode[i]; document.getElementById("selsize").options[i] = new Option(sizelist); }}
</script>
In an event, i'm passing in "BLK" as the colorcode param. This is creating my selsize select box with B, L, K, and undefined options until the for loop finishes. ie, its taking the passed in colorcode as a literal string, instead of referencing the array. Anyone have a pointer as to how i can access the arry, instead of the literal string?