I need to iterate through a group of arrays and search for a user-chosen word every time.
The problem is i can't declare how many array elements will be needed, such as: new array = (12), because some words inside my arrays, occur more than others.
So i need to decalare an empty array with x number of possible values.
How to declare and initialize an array with key/values using JavaScript and then dynamically creating select dropdown and assigning key/values to the options using JavaScript?
I am looking for a push in the right direction for a few problems i am running into; my first problem is I have to create a script element that contains the function amountTotal which should return the sum of all the values in the amount array. There are no parameters for this function, and I have to add the following commands to it.
1. declare a variable named total with an initial value of 0
2. create a for loop thatloops through all of the values in the amount array, at each iteration of the loop, add the current value of the array item to the value of the total variable.
3. and after the for loop is completed, return the value of the total variable.
The amount array has already been created and populated in a list.js file, I had to first create a script element pointing to it.
This is what i had for my link to the list.js file and funtion :
I have my entire code written but i am trying to break it up and fix my problems 1 at a time: when i open the code, it does'nt display correctly ( which is another problem) but I ran the debugger and it says my total is undefined. ( this is in another section of my code), but I guess my function is wrong somewhere.
im currently working on a web app which uses heavy javascript. in one of the functions, a simple array is created using "var admin_types = new Array();". This array is not empty, it has a length of 0 but contains one element with the name "clone" and the value
function () { var copy = {}; for (var i in this) { var value = this[i]; try { if (value != null && typeof (value) == "object" && value != window && !value.nodeType) { value.clone = Object.clone; copy[i] = value.clone(); } else { copy[i] = value; } } catch (e) { copy[i] = value; } } return copy; }
why does this element get created?? The weird thing is that i use a lot of arrays and this is the only one that has that element.
i tried this in firefox 1.0, ie 5.5 and mozilla 1.7.1 and the element is in the array for all of them...
I have the following code which will split the given input based on the comma(,) and will store each value in separate address of the same array.[code]...
How can we remove the empty values while displaying the output or how we can remove the spaces from array+
What type of variable is an empty array element? I thought it was undefined, but i noticed that they have different behavior than undefined does:
var r=Array(1); var s=r.concat([0,"",null,undefined]); alert (s.toSource()) //==="[, 0, "", null, (void 0)]" typeof s[0] //==="undefined" typeof s[4] //==="undefined"
As you can see, 0 and 4 both === undefined. Yet, they don't have the same toSource()... Is this special type named anything specific? Or more importantly, can it be detected outside of an array as being distinct from undefined? I am thinking this would be the same type as ({}).nonProp ... I guess the question is actually, "can you tell the difference between uninitialized and undefined"?
I'm not an expert with javascript nor am I too familiar with the syntax. What I'm trying to do is store all errors into an array like so:
Code JavaScript: var errors = new Array(); var example = ''; if (example == '') { errors[] = 'This example field is empty'; }
What I'm trying to do at the end is display the array if its not empty into a DIV called errors (or something). I know how to do this in PHP but I'm trying to do first validation layer through javascript. So something like this:
Code JavaScript: <div class="errors"> if (errors != '') {//If the array is not empty for (keyvar in errors) { document.write(array[keyvar]);//Display Errors } } </div>
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);
I am doing a password reset form using Jquery and PHP. If I try to submit an email id it should sent and email and report back the response text as success so that the user knows email has been sent. But I am stuck with JSON submit as I have an empty array to decode at the serverside. I am using minified version of json2.js from the official json.org website
Here is the code. Code JavaScript: var formdata = $("#log-box").serializeArray(); formdata = JSON.stringify(formdata); var notifymsg; alert(formdata); $.ajax({ type: "POST", url: "forgot-pass.php", contentType: 'application/json', data: formdata, success: function(responsedata){ var some = responsedata.split("&"); $.each(some, function(index,value){ //alert("index="+index+"value="+value); }); }, error: function(o, s, e){ alert("Form not posted "+e); }}); formdata alerted gives: [{"name":"email","value":"ravi.k@gmail.com"},{"name":"acctype","value":"loginaccount"}]
I prefer to keep all my scripts in an external '.js' file. I am currently loading the external '.js' file from the header. Problem is I would like to declare a global variable in the external file, but I keep getting an error about the object does not exist.
Can someone tell me where or how to declare a global variable in an external file that is available after the page is loaded.
can anybody put forward a sensible argument javascript's behaviour of creating a new global variable whenever I assign to a previously undeclared variable. I can't beleive this is just for the sake of convenience (surely we learned this much from basic).
here's my proposal: all "global" (document scope) variables must be declared by 'var' outside a function block.
failing that, does anyone know any patterns or tricks I can use to make sure I don't create a new global variable when I accidentally misspell a variable name?
How do i declare a default value in a function? I have a simple function
function color_input(id,token){ if (!empty(token)){ document.getElementById(id).style.backgroundColor = '#2A2A2A'; document.getElementById(id).style.color = '#DDC58C';
[Code]....
You will notice that the #2 parameter is missing in the html call. Sometimes i don't have it to send. in PHP i would just set the functions second param like token=''
I have a problem with customer website.My script creates an Auto-Greet that overlays the page, displays in the lower left of the browser and remains visible as the user scrolls the page.
My Mockup the customer home page. This is the desired action.http:[url]....Customer website: (undesired action)http:[url]....The only difference is that my customers does not declare a .dtd document.They have a <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">. On my mock-up, I declare a .dtd document and my script works.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http:[url]...
Question: I'm trying to figure out a way in javacript to dynamically change the <!DOCTYPE, is this possible?
Well, I've been working with JS for three years and have a great experience here. But! I still have no really acceptable answer to the following question:
What is the principle difference between declaring methods/properties in the constructor function body and via prototypes.
Are there any real GURUs? Let's discuss the issue.
I find ajax with jquery more confusing than with regular JS, b/c in jQuery you don't declare XMLHttpRequest object.. so how do you do something like:
In example I mention here,[url] namely [url] I don't understand where var 'msg' is declared, I know it comes from the back-end, but HOW is it passed to the front-end? (how do you do this w/o responseText or something similar?)
I'm trying to connect to a send-mail jsp with ajax.. the email is not getting sent.. I want to test if the ajax connection is being made at all.. don't know how do it w/o something like xmlHttp.responseText
This is my jQuery ajax code for connecting to send-email jsp:
var dataToSend = "name=sName&email=sEmail&msg=sMsg;
I have been working on a few budget scripts that I can access from the web in using HTML. My problem is that when variable values change I need to change these values in all of the HTML files on the server. I know that there is a way to declare global variables in a single file and use those values in another file but I have not been able to find any information that tells me exactly how to do this. I have tried to put it together on my own using what little informaiton I have been able to find but have not been able to get this to work. Is there a more detailed referance that I can find somewhere or does anyone know what steps I need to take to make this happen?
I have a function which has a nested function in it. I need some variables in the first function to be available in the nested function. How am I supposed to declare a global variable in jquery?