I am using jQuery 1.4.2 and I am trying to carry over the global variable totaltabs into my JSON callback function. The code seems to work properly, however, in my loadJSON function after the callback function loads the data, my totaltabs variable will not increment.
Here is a peak at my code.
totalItems is loaded from another function, not relevant to my example.
Code JavaScript: var totaltabs = 0; $(document).ready(function(){ resize();
i have this problem in passing values to a variable in a jquery function.
i have a js variable that accepts a certain value and then i want to pass this variable in the jquery function.
For example, this is my script: var autoScrollBool = "true" var autoScroolInt = "10" (seconds) stepcarousel.setup({
[Code].....
i want to replace the value of autostep: {enable:true to enable: utoScrollBool(the variable i created) , when i tried to assign it as is, its not working.
I've got a function displayResults(imageArray); that first calls removeElements(); to get rid of the currently displayed list items. Both functions are part of class function eventBox(array, string, date). both displayResults(imagearray); and removeElements(); have been bound to eventBox(); by e.g. this.removeElements = removeElements;
However, from within displayResults(imageArray); this.removeElements(this.identifier + "eventsul"); evaluates to "undefined". Also, this.identifier called from within the function also evaluates to undefined (it doesn't in other functions). For some reason I can't access global functions and variables from displayResults(imageArray);. Any ideas?
Here is the code for displayResults(imageArray); :
How can I have global variables and global arrays whose value(s) can be modified and accessed by all the Javascript functions in my HTML document as well as by the HTML code?
I've googled this and found a few different explanations that (as a PHP developer) are making absolutely no sense to me. I'm a total beginner with Javascript (not just jQuery) so a little help would go a long
I cannot findout how I can write to global variables in a a JQUERY function. <script type="text/javascript"> function checkusername (username ) { $.post("[URL]", { action: 5, username: username }, function(xml) { result = $("apot", xml).text(); //<-- this variable is not global... why ?? message = $("message", xml).text(); //<-- this variable is not global... why ?? alert(message); //<--here variables are shown ok alert(result); }); alert(message); //<--here variable is NULL !! alert(result); //<--here variable is NULL !! } </sctipt>
I'm having trouble letting functions I defined in jquery read javascript global variables I defined elsewhere.. for example I have a function defined within my jquery
$(document).ready(function(){ function performTabSlide() { // do something with currentPosition;
I have a problem with understanding jQuery. In my case I have this JS file with following content (see below). This is an anonymous function, isn't it? The problem is this line:
function openWindow(windowName){ timeStamp = new Date(); var timeStamp = timeStamp.getTime(); document.getElementById(window).style.display = 'block' }
blahblahblah . . . openWindow('order'); // calls openWindow function and sets timeStamp variable. alert(timeStamp);
then I get error: timeStamp is undefined. Why? I defined it as a global variable within openWindow. Am I just doing this wrong?
I`m building a site with html and GIF files on one server and audio files on another. That means I have to use absolute references to the audio files.
Problem is, the site will probably dwell some day in other server(s), and may also use a different audio format. I like to be able to globally change url strings and suffixes of the referenced files.
I think I can`t use "base href" because relative references (to files that are on the local server) would be affected.
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.
Is there a way to "pass" an XMLHttpRequest object to the callback function for onreadystatechange? Or a way to access it from onreadystatechange? I would like to avoid the use of a global variable...
Example:
/* How do I get rid of this global variable? */ xmlHttp = new XMLHttpRequest();
function myFunc() { ... xmlHttp.onreadystatechange = myCallBack; ... }
function myCallBack() { if (xmlHttp.readyState != 4) { return; }
//document.write("Test"); //Declare arrays stats = new Array(6); statMods = new Array(6); /* //Populate stat and statMod arrays
[Code]...
without first calling the other function that actually assigns values, it still works. As I said, though, if I assign values outside that function, then it all falls apart.
i am having two global variables and i m setting their values on calling some function. After setting the values, i call a function in an object ...
if MyHint is an object and i am calling the function in it, but i am getting the values of global variables as undefined in the function of object MyHint. Is there any way to access the value of the global variables.
I'm new to javascript, but I need help and really hoping for a reply. I was trying to find an answer in Google but no result. So I have two table containing images, at the beginning only first table is displayed. Then when one of the images in the first table is clicked, a second table should appear, and user should click one of the images on that table. And that image should replace the one that was clicked originally in the first table.
So the question is, when the user clicks an image in the second table, how do I know what was originally clicked in the first one? I tried to use global variable but that doesn't work.
I have some JavaScript which is splitting out the different variable elements from the URL.Now, how do I set the internal variables?Then I want to set the variable ScriptHeading to be Change and the variable ScriptType to be NewThread.I keep finding all sorts of lovely code showing how to split out the various sections in many different ways, but I can't find anything on how to actually set these variables.
I have an HTML page which loads another page inside an IFrame. Each of the two pages has its own javascript code.
I would like to be able to define one global variable which will be accessed from functions in both scripts. The variable must be single. That means that if a script in one of the pages changes it, the change will be seen by the scripts in the other page.
I have an external js file used by an html page but I want to use global variables defined in the html page in the js file. for example...
<html> <head> <SCRIPT type="text/javascript" var test = "1"; </SCRIPT> <SCRIPT type="text/javascript" src="jscript.js"> </SCRIPT> </head>
So I have var test which is defined in my .html but my jscript.js also uses the variable. I am doing it this way because I have a lot of pages that are simular using the jscript.js functions but each page has different quantities and values of variables used.
I have been struggling with a form wizard all day. I'm using jquery stepy (form wizard) along with validation plugin. To cut a long story short, my first step is to get MySQL connection from form controls details. On submit ('next' button) a check is made on an empty hidden control ('hid').
So, if the function checkDBData passes, false should be returned, so that the form can progress to the next step. If the connection details fail, true is returned so that an error msg is posted.
Here's the checkDBData function: function checkDBData(){ var host = $('#mysql_host').val(); var username = $('#username').val(); var password = $('#password').val(); var dbname = $('#dbname').val();
The return values don't find their way back to the rules. However, if I hard code false and true to the function... function checkDBData(){ var host = $('#mysql_host').val(); var username = $('#username').val(); var password = $('#password').val(); var dbname = $('#dbname').val();
$.post("install/sqlcheck.php", {"host": host,"username": username, "password": password, "dbname": dbname}, function(msg){ if(msg.required == false){ return false; }else{ return true; }}, "json" ); return false; //or return true for testing purposes } This works. I assume it's due to the asynchronous nature of the ajax call.
I have the code this way in order to consolidate it since I would prefer to do that instead of checking the selected ID and manually checking against all possible IDs (which works flawlessly, it just takes up about 5x the lines and is not modular). What I have above also works, but there is one fatal flaw:
It seems like the anonymous function that is the onclick for each unselected element becomes "return changeTo(tab + '_id')", but I don't want it to be that. I want the argument to actually be what tab is instead of the variable.
What ends up happening is that after changeTo() is called for the first time, any element you click will result in the last element being the selected one, as if it's using the final value of tab as its return value.
This doesn't make any sense, though, since tab is local, and deleting it before the function exists doesn't work. Deleting elem at the end of the for loop doesn't work. I honestly don't understand what's going on or why it doesn't set the new onclick value correctly.
Basically I just want changeTo(tab + '_id'); to turn into changeTo('MYID_id'); instead, but it simply doesn't do that and I can't figure out a way how.