Given a JavaScript "array" (ok, so really they are "objects" but it's being treated as an array...) in the format
HTML Code:
var patient_code = "0"
var header_id = "1";
var question_id = "1000";
fake_data_array["patients"][patient_code][header_id][question_id]
HTML Code:
var fake_data_array = new Array();
fake_data_array["heading_information"] = new Array();
[Code]...
What's happening is, '1000', '1001', '1003', '1004' are being cast as integers, not strings, and it's "filling in" the first ~999 keys as 'undefined' so the length is returning something like 1005, not 7. I'm manually writing the arrays now, and will eventually be building this massive js array from a collection of existing PHP arrays. Is there a way to forcibly cast the values as strings?
Firstly, apologies for my terrible JavaScript knowledge! I'm getting there! I have an array that is made up of the results of a few SQL queries. The queries return the record id and an integer. I need to sort the results of the queries by the integer. I am trying to store them in an array, using the record is as the key, then sorting the array. However, when I try to get the data out of the array, it has changed the key!
E.g. Original results [10605] = 141 [10744] = 116 [18835] = 166 [15304] = 166
I would like to have an array and define which element goes to what key. Something like this: Code: var test = [][]; test[0][0] = "foo"; test[0][1] = "bar";
However I am wondering if its possible to write it in one statement? Something like this: Code: var test[0] = [ [0] => "foo", [1] => "bar" ]; The code up doesn't work of course.
I'm trying to present a collapsible list if keys which when expanded will have a delete button at the end of it. My problem is that when this code runs, the confirmation alert shows the key name as the last one read from the array for all items. Here's the complete function:
[Code]...
why this code invokes the deleteNote function with the last key name for all notes?
I am making a php/mysql epos system for my shop which will be run from a browser on my shop PC. I have large buttons which I would like to be able to 'click' by pressing something like the F-buttons at the top of the keyboard. Is it possible to override the standard button shortcuts for a web page. This is only going to be on my shop computer so accessibility is not a problem.
this string will evaluate to a 2D array if I do this:var array = eval(string);But eval is not very safe.Is there a way to achieve the same effect (turn that string into 2d array) without using eval function?And I have no control over what string I am given, so will have to process this kind of a string =Right now I am thinking of writing a custom function which will split the string and then split again etc, but is there already something that can do this job?
So i've written up the code to do a lightbox esque overlay image gallery. everything is working smooth and fine. The only concern is that I have the following:
lets say that I have a page that has multiple galleries. Obviously I would have to make each literal array with the gallery data different names, ex:
obviously "galVariable" would be undefined... as i'm trying to get "_gallery2.images" but trying to use "galVariable" to point to "_gallery2"
I'm familiar with solving a problem like this in PHP, not so much javascript. is there a JS function that can be used to ensure that it's using whatever "galVariable" equals to, and then that array's content is? Or is there a different way to go on about this.
What I'm trying to do, I think, is to use elements of an array as a part of an object. Here's a lil' code snippet:
Code:
I'm trying to insert each of the elements of the katMusik-array into the checked-line, thus checking the checkboxes with those names. However, it doesn't seem to work.
I am getting a string with the value of the clicked button from an array and some other select field values that are listed in the same set of mysql results as the clicked button.At the end of the script the page is redirected to in the script mentioned page with following string:process.php?value=1&bs=2&ad=3&ns=4&wt=5&in=6 Is it possible to make locationstring variable global and in a single line in order to be able to use the full string in other scripts or is there another solution.
I'm trying to turn an associative array key into a string. I know I can do that in php with a foreach loop like foreach ($array as $key => $value) and then I can do whatever I want with the key. I want to be able to loop through a javascript array using a for in loop and test to see if the key matches part of the name attribute of some inputsIs there a way to do this? I looked online and I found a way to turn a string into a variable name but not the reverse
The values I have in variable "tables".I want to create variable list which takes values from "tables".Than I want to split this, and put each value in to new array: I've started with:
var list = "tables"; var listArray = list.split("|"); for(i=0; i < listArray.length;i++)[code].....
I'm not entirely familiar with the norms and standard libraries of JavaScript so if the answer to this is yesterday's news, please ignore.
I'm trying to write a simple text formatting function to make headings proper case -- i.e. first letter of words capitalized.
I first tried this...
function inProperCase(s) { var result, i, k; i = 0; result = s.toLowerCase(); while ((k = result.indexOf(' ', i)) -1) { if (k - i 0) { result[i] = result[i].toUpperCase(); } i = k + 1; } if (result.length - i 1) { result[i] = result[i].toUpperCase(); } return result; }
...but it didn't work. To my amazement, you cannot set a character in a string by accessing that character with an index, like so:
s[i] = ch;
Must be because JavaScript strings are "Immutable" or "EtchedInStone" or something. (Just kidding, no flames, please. I'm sure it is more efficient.)
The only thing I could come up with was this (with some details, like the "compound" while predicate, modified into a more readable form after being called a "C-bigot" by a friend :)) which seems pretty heavy-handed with all the string slicing and concatting:
function inProperCase(s) { var result = s.toLowerCase(), i = 0, k = result.indexOf(' ', i); while (k -1) { if (k - i 0) { result = result.substring(0, i) + result[i].toUpperCase() + result.substring(i+1, result.length); } i = k + 1; k = result.indexOf(' ', i); } if (result.length - i 1) { result = result.substring(0, i) + result[i].toUpperCase() + result.substring(i+1, result.length); } return result; }
You call this as...
inProperCase(" madam i'm adam ");
...and you get...
" Madam I'm Adam "
Any suggestions for making this a bit more elegant?
BTW You may point me to a "library" with a super-efficient implementation of this function, but that is not the point. My issue is, how do we update single characters in a string (or single items in an array) in JavaScript? Is it something like...
I've searched on the form and found answers but I cant get it fix for me. want to make a form with multiple rows with checkboxes. Firt I did it in PHP and it worked but I want to use Jquery. How can I get the checked checkboxes to a string?It thought it would be something like this (found it on this site):
var test = $(':checkbox').map(function() { return this.id; }).get().join(',');
I am trying to search an array for a string and then if it is found alert it. I have found examples of how to iterate the array and how to use .IndexOf to return a true false statement as to whether the array includes the string, but i don't know what to do after that and how to display the string if its found.