Jquery :: Access Variable From Another Function?
Feb 28, 2009Does any one know how to access variable from other function in jquery ?
View 8 RepliesDoes any one know how to access variable from other function in jquery ?
View 8 Replies<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var global_var = false;
function test_func() {
$.post("server.php", function(data){
alert("Data Loaded: " + data);
[Code]...
In one of my functions I got the following lambda function. It works as intended, but I got a tiny problem. I'm trying to access the function-scooped variable "matched" and set it's value to "true". The problem is that it seems like the variable is existing as a local variable inside the lambda function, even if it's not declared inside the lambda function itself. So, the change "matched = true;" does not effect the variable that I declared.
Code:
//... code
var matched = new Boolean(false);
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
[Code].....
how would i build a multidimensional array? would it be: PHP Code:
var rinksAndPriceArray = new Array();
rinksAndPriceArray[0] = new Array();
rinksAndPriceArray[1] = new Array();
i've figured that out so far.
now, i want to be able to access a part of one of the arrays based on a variable that is passed into the function
the variable i'll send in will be the first part of the array ex: rinksAndPriceArray[0][0] and i'll want to return the rinksAndPriceArray[0][1] value.
I have a class and function within it, like so
[Code]...
That code shows an alert box with 'mb_c is 1' and next alert box as 'other mb_c is undefined'. How do i access the mb_c which is member of Order class within the setup function which has an argument mb_c ?
I am simply trying to use a global variable in javascript, but can only access the variable on the second call. I can't find anything that relates to this through my searches. My application is supposed to query the server for XML that tells me which years and months are available to put into combo boxes. I want to store this xml in a global variable to access it later.
[Code]....
I got a simple plugin as below:
Code JavaScript:
$.fn.ajaxSubmit = function(options){
var submisable = true;
}
I want to to able to access the variable submisable from outside the plugin like doing something like below:
Code JavaScript:
$(function(){
$('form').ajaxSubmit();
$('div').click(function(){
[Code]....
I need little help with arrays :))
[Code]...
why I cannot access json data by using a variable as a node name. I'm trying to grab a random quote from a .json file and display it in a div. When I access a node in the object by node name I can access the node data. However, when I try to use a variable in place of the node name (because I want to grab a random node) I get an object undefined error.
JSON object:
{
"quote1" : {"quote" : "hello, world."},
"quote2" : {"quote" : "goodbye, world."},
"quote3" : {"quote" : "out of this world."}
[Code].....
I'm trying to access a variable that's set when the plugin is initialized. I'd also like to change that variable on the fly.
(function($) {
$.fn.plugin = function(options){
// default settings
var settings = {
[Code].....
I'm trying to populate a web page with javascript. I have 2 functions. One that runs on-load so I can populate a dropdown list. The second one to process the selection when the user selects an item from the list.
I have a global variable in the top of my javascript that I use in the functions and as long as I set it in it's global scope, everything works fine. But what I really want to do is to pass this into the javascript running on this page via the code...
My question is. Where do I put this code so that I can use it to set the global variable "weekNumber"?
I've tried putting this code in the populateList function - NOPE! I've tried referencing it via window.weekNumber and this.weekNumber - NOPE. I'm stumped.
I've spent far too many hours trying to understand this without success. Can anyone help me figure out where to put this code so I can set the global variable weekNumber?
Is there a better way to do this?
I need to acsess an object property via variables, but don't get ahead.
Example:
var property = height;
"height" is a property of the object "flower". Now, I need a possibility to access "flower.height" with my variable property, means -->"flower.property" I tried everything like "flower.[property]" "flower.['property']" etc. but nothing did help.
I was wondering how to access parents class variable. For example:
Code:
function Class(){
this.variable; }
SubClass.prototype = Class;
SubClass.prototype.constructor = SubClass;
function SubClass(){
this.secondVariable = Class.variable; <-how to access parent variable?
}
[code]how i can set context/scope for myStartAction so it can access (this.url) variable?console.log(dd.url) will work but i can't predict what name will object have (that depends on user) there might be more than one instance of myObject
View 10 Replies View RelatedWell, it turns out IE8 has yet another problem. My code has a global variable (to the object) inside an object declaration that cannot be accessed by a function (that is also global).
The code is like so:
Code:
function myobject(params){
//public
this.initialize = function(){...}
//private
some variables...
//problem variable
var mouse = new Object()
mouse.x = 0;
mouse.y = 0;
//code...
slidecontainer = document.createElement("div");
slidecontainer.onmousemove = function(event) {
if(boo.isIE) {
e = window.event;
mouse.x = e.x + document.body.scrollLeft;
mouse.y = e.y + document.body.scrollTop;
} else {
e = event;
mouse.x = e.clientX + document.body.scrollLeft;
mouse.y = e.clientY + document.body.scrollTop;}}
//this function is in an interval
function moveslides() {
/* this is where I have the problem
It seems that the function doesn't recognize that mouse.x, or mouse for that matter, exists. Mouse is global to the object, so why can't this function access it?
*/if(mouse.x) {
code...
}}}
The page is at [URL] and works on every browser, including finnicky opera, except for ie. The full code is availabe when you right click and view the source on the page.
<html>
<head>
<script type='text/javascript' src='jquery-1.4.2.js'></script>
<script type='text/javascript'>
$(document).ready(function(){
[Code]...
The above is a simplified example of the problem I'm facing. I could merge functions into one big self-referencing function (i.e. recursive function), but that's ugly and causes other problems (such as when insert form elements and wanting to harvest the user input afterwards). I considered declaring a variable in the top ".ready" function, and have all child functions stuff their HTML changes in it, but that seems to be a pain to keep track of and removes much of the value of using jQuery in the first place...
Is there a nice solution for this? To, after inserting HTML, somehow update the HTML state referred to by jQuery in the non-local scope(s)?
I am trying to access a variable that is return from the "success" setting from an $.ajax call. I am not sure how to do this. I have attached the code below. Maybe there i a different way to get this variable?
[Code]...
I am trying some simple things with javascript and trying to use it in a object oriented way. However I am now facing a problem in which I can't access an object variable from an object method. I am using jQuery.
My code is as follows;
Code:
My problem is that the variable msg1 does not work when accessed from function called from the jQuery get function. I get the message undefined. Therefore I am wondering, is there a way how I can access msg1 of my object instance from the get function of jQuery?
I am trying to declare a variable inside a function and use it later on in my code... but it just already returns white space... i.e. not variable value. I am setting it within this function:
function show_video1(){
document.getElementById('video1').style.display="block";
var video1Name = "Education World News (Part 1)";
document.getElementById('video2').style.display="none";
document.getElementById('video3').style.display="none";
document.getElementById('video4').style.display="none";
[Code]...
and trying to call it later on with this: <script type="text/javascript">document.write(video1Name)</script> It might be worth noting that each one of my 11 videos will hace a different name.
So I've got this checkbox thing going on, where an array converted with the value of each checkbox in it.It looks like this:
[Code]...
What I want out of this function is the variable newworkdays to use in another function.
How do I access the "newworkdays" outside the function? I've already try to declare the variable outside of the function, though that resulted in that I didn't get the value of the variable inside the function.
I have this script
Code HTML4Strict:
<head>
<style type="text/css">
.correct_field
[Code]....
Which does not work, what I am trying to acomplish is set the class of an object, if I do the whole thing inside a function it all works, however if I create another function that calls a second function it does not, how could I use the object that fired the event in the numbers() function?
I have HTML page which use js function and worked fine b4 I pull out the javascripts function from that page.Then later, I created .js file for the js functions and test again, the function doesn't work anymore.
In .js file,
<script type="text/javascript">
var upload_number = 2;
function addFileInput() {
[code]....
When I click on the Upload another file link, nothing appear.It worked b4 I create separate js file.
I am having trouble loading a drop down menu list script that I got from Dynamic Drive.Here's the original test page. (Works Fine)
<html>
<head>
<script language="javascript" src="http://www.modbargains.com/images/Javascript/ChainSel/chainedmenu.js">
</script>
[Code]...
I am not sure if the function is correct but it does not work. Any ideas how I can make this work????
I am working a project for school in which I am trying to make a simple math game. When the user clicks the start button it will bring display a question and ask for an answer. What I want to to is when the user clicks the start button it will swap the button for to other buttons to move to the next question and one to restart the game. Which works fine, the problem is after the buttons are swapped.
How would I access a sub function from a buttons onclick event? I currently have onclick="return MathGame.resetForm();" but that throws an exception and I can't see where. What is the best way to go about this. Also this is my first attempt at using javascript in this manner so I'm probably going about it the wrong way.[code]...
I am mixing javascript and php to graph sales dynamically from a mysql database - unfortunately i can only plot 1st sales value - i basically need javascript to call a php function that queries the database and returns the next sales value - here is a snippet from the php file [code]...
View 2 Replies View Relatedin the body tag, I have this code (just to test):
<script LANGUAGE="javascript">
<!--
function hiThere() {
alert("hi");
return true;
}
//-->
</script>
in the head section, I have this code:
<script LANGUAGE="javascript">
<!--
document.body.onload=hiThere();
//-->
</script>
By the way, I know someone will comment, by "does not work, I mean on
the load of the page, the alert is not displayed, nor are any errors.
Thanks for any help you can offer.