Mozilla And Global Scope
Jan 22, 2005
I've just realized that in Mozilla pointer variables always have local scope in a function. Unlike IE. I wondered if Mozilla was able to do it in some other way? readXML() is an init() function which might be a constraint - I'm no javascript expert.
// The following won't work in Mozilla.
var record;
function readXML()
{
record=xmlDoc.getElementsByTagName("record");
}
alert(record[0].childNodes[1].firstChild.nodeValue);
View 4 Replies
ADVERTISEMENT
Jul 19, 2010
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;
[code].....
View 3 Replies
View Related
Jul 14, 2010
I'd like to move the global variables vertexBlaBuffer to the scope of the Geometry prototype [code]...
View 1 Replies
View Related
Jun 10, 2011
I created this code for a sliding panel and it works well. But I'm struggling to take the object oSidebar out of the global scope. I would prefer that it were a property of the clicked event object. That is, I want to be able to use 'this.oSidebar' within the click event. I've posted the whole page here along with the click image.
[Code]...
View 1 Replies
View Related
Feb 2, 2011
I wanted to write my own script for a fade-in animation, since the ones I have found have got too many options or need some framework, which makes them unnecessarily big. I wanted to learn too.Unfortunately, the code didn't work as I wanted, and I commented some things so as to find out what's happening.Why is an object reference assigned to what was previously a string?
View 6 Replies
View Related
Jul 16, 2009
had this in browsers areas but people told me I should put it here in Javascript because more people here would probably have seen it before and know why it happens. I have basic Javascript that rotates images. I've noticed any kind of Javascript code that rotates images has this same problem only in Mozilla. When the images rotate in Mozilla in between the rotations, Mozilla browser adds a little colored square that represents a blank image that are able to be seen does anyone know why Mozilla Browser adds that? For example when looking at this page in Mozilla can see it. if you know if this is some Mozilla problem with Javascript and images. Doesn't happen with IE and other browsers shows the images only and nothing else.
View 2 Replies
View Related
Mar 2, 2010
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?
View 1 Replies
View Related
Nov 30, 2010
I've a BIG Problem With a HUGE JS application , i'm modifying its javaScript code to work on both IE/Mozilla , currently it works fine on IE but not on Mozilla.
My main Point now is events.
Lets try with a little module, consider this function :
And it is attached in this place like :
This works fine in IE , i want to modify it to work on Mozilla.
View 2 Replies
View Related
Jan 19, 2011
got a problem with this snippet...
function writeColum () {
var x = document.getElementById("wc").value;
var y = document.getElementById("title").value;
if (event.keyCode == 32) {
[Code]...
View 7 Replies
View Related
Oct 11, 2006
I'm trying to write an 'each' function for a JavaScript array that
behaves like Ruby's Array#each. (It doesn't matter if you know Ruby to
help with this question.)
My problem is the scope of 'this' inside the iterator callback. I would
like it to be the same as the object that called the each() on the
array. Right now I have to do that with a closure or an
explicitly-passed 'this' scope. For example:
function Person( inName, inCats ) {
this.name = inName;
this.cats = inCats;
}
// Using a closure
Person.prototype.showInfo = function( ) {
var me = this;
this.cats.each( function( catName ){
alert( me.name + " owns " + catName );
} );
}
Array.prototype.each = function( inCallback ){
for ( var i=0,len=this.length; i<len; ++i ){
inCallback( this[ i ], i );
}
}
phrogz = new Person( 'Gavin', [ 'Fuzzles', 'Kitty' ] );
phrogz.showInfo( );
--Gavin owns Fuzzles
--Gavin owns Kitty
// Using an explicit scope
Person.prototype.showInfo = function( ) {
this.cats.each( this, function( catName ){
alert( this.name + " owns " + catName );
} );
}
Array.prototype.each = function( inScope, inCallback ){
for ( var i=0,len=this.length; i<len; ++i ){
inCallback.call( inScope, this[ i ], i );
}
}
Inside the each() function, arguments.callee.caller would give me a
reference to the showInfo function object. What I am looking for is a
way to access the scope of the 'this' receiver within that particular
invocation of showInfo(), so that I can use it in place of inScope
without having to pass 'this' each call.
View 9 Replies
View Related
Jul 20, 2005
If I do . . .
myForm=document.tstForm;
function initialSetup(){
myForm.fld01.value="Test 01"
myForm.fld02.value="Test 02";
myForm.fld01.focus();
}
Then, in the body tag, I do onLoad="initialSetup()",
the script doesn't work and I get a "myForm has no properties" error
I know it'll work if I move it within the function, but I figured a
global variable would retain its value within the function. Why not?
View 2 Replies
View Related
Jun 26, 2007
In the method nextImage, I can't figure out how to access thumbs. It keeps coming back as undefined. (Using Firefox)
function runPortal(portal_number){
// there are multiple runPortals on each webpage
this.portal = document.getElementById('portal'+portal_number); // represents the div that holds the images
this.thumbs = this.portal.getElementsByTagName('a').length; // represents all the images within the div that will be rotated
this.length = this.thumbs.length; // that's how many images will be rotated
// Hide everything
for (var j=0;j<this.thumbs.length;j++){
if (j==0) continue; // Don't hide the first one
this.thumbs[j].childNodes[0].style.display = 'none'
}
this.nextImage = function (){
// there are a fixed number of images to rotate. Start over
if (this.i >= this.length){
this.i = 0;
}
// One fades away, the next appears
Effect.dglPuff(this.thumbs[this.last].childNodes[0], {duration:.6, from:.7});
Effect.Appear(this.thumbs[this.i].childNodes[0]);
// iterate to the next image for the next run
this.last = this.i;
this.i++;
}
// Set up the image rotator
// here is where I started guessing
// thumbs needs to belong to the object rotator, I guess.
this.rotator = new PeriodicalExecuter(this.nextImage, 4); // This object runs the function every 4 seconds
this.rotator.portal = document.getElementById('portal'+portal_number); // represents the div that holds the images
this.rotator.thumbs = this.rotator.portal.getElementsByTagName('a'); // represents all the images within the div that will be rotated
this.rotator.length=this.length; // that's how many images will be rotated
this.rotator.i=0; // the counter for what image we're one
this.rotator.last=0; // the counter for the previous image
}
View 5 Replies
View Related
Jul 23, 2005
Given the following working code:
function attributes() {
var attr1 = arguments[0] || '_'
var attr2 = arguments[1] || '_'
return (
function (el1, el2) {
var value1 = el1[attr1] + el1[attr2];
var value2 = el2[attr1] + el2[attr2];
if (value1 > value2) return 1;
else if (value1 < value2) return -1;
else return 0;
}
);
}
var a = [
{ a:'smith', b:'john' },
{ a:'jones', b:'bob' },
{ a:'smith', b:'jane' }
];
a.sort(attributes('a', 'b'));
for (var i =0; i < a.length; i++) {
document.write(a[i].a + ', ' + a[i].b + '<br>');
}
My question is, are attr1 and attr2 guaranteed to exist through
the lifetime of a.sort(attributes('a', 'b'))?
As I understand it, the anonymous inner function reference I am
returning is a property of attributes(). As such, when I return a
reference to the anonymous inner function, the outer attributes()
function must continue to exist (as must attr1 and att2) until
there are no further references to the inner anonymous function.
As a result, there is no danger of attr1 or attr2 "disappearing"
during the repeated calling of the anonymous inner function.
Is my explanation basically correct, or am I deluding myself and
I'm just lucky that the garbage collector hasn't recovered attr1
or attr2 while the sort is still going on? In other words, is the
behaviour I'm seeing consistent and predictable, or should I
change my approach?
View 3 Replies
View Related
Jul 23, 2005
I have a script in which a function launched by a START button
continuously calculates and writes a value to a text box. The
calculation is done in a for loop. In the loop is a conditional that is
a global variable, a boolean. If the boolean is true, break ends the
loop (or is supposed to!). A STOP button has an onclick function that
sets the global variable to true.
What happens, though, is that the function for the STOP button is
not executed until the for loop reaches the maximum value set for i.
Anyone know how you can get one button to stop a process started by
another?
View 4 Replies
View Related
Apr 6, 2006
I had a need for a two dimentional array. Looking for this solution, I
ran accross a statement than all Javascipt arrays were arrays of
objects. So I created a function prototype, at least thats what I was
calling it:
function objRow(vartype, varaddr1, varaddr2)
{
this.type = vartype;
this.addr1 =varaddr1;
this.addr2 =varaddr2;
}
Next I did:
var myobject=new objRow("1", "1234 Main St.", "Apt 101");
At this point I was able to see myobject.addr1 or any other variable in
the object instance.
Now I added this object to a table.
var aryTestTable= new Array();
aryTestTable[0]= myobject;
At this point I could see
aryTestTable[0].addr1
Next I tried an additional object
myobject=new objRow("1", "1234 Main St.", "Apt 101"); //with
different data
And added it to the table
aryTestTable[1]= myobject;
Where I could see:
aryTestTable[1].addr2 or any other variable.
so far so good. Then I started the actual application code where I was
reading a database table and creating the objects and adding them to
the table. This was in a for loop wherein the myobject=new objRow("1",
"1234 Main St.", "Apt 101"); was instantiated.
After the for loop was finished, I could not access the data in the
table - undefined.
So my questions are: Have the my object instances popped off the stack?
and What is the alternative way to implement this table of rows of
values.
View 4 Replies
View Related
Apr 4, 2011
I'm showing a form in a Simplemodal dialog in combination with ajaxForm() to redirect the resulting page to another DOM element. The success function of ajaxForm() closes the modal dialog.The resulting page in the other DOM element has no access to the jquery function $(). When I load a page using ajax into the DOM element there is no issue access the jquery function, this only happens when I redirect the resulting page from the ajaxForm() function.
View 3 Replies
View Related
Sep 8, 2006
I'm trying to access some of the global's inside my class LiveSearch
and I have no idea how to go about it. Here is what I have so far:
<script type="text/javascript" src="query.js"></script>
<script type="text/javascript">
function LiveSearch(global) {
this.theglobal = global;
this.initialize();
}
LiveSearch.prototype.initialize = function() {
$("#thebutton").mousedown(function() { //when we click the button
alert(this.theglobal);
});
}
$(document).ready(function() {
var objSearch = new LiveSearch("globalvalue");
});
</script>
On page load I create a new LiveSearch instance and it assigns
theGlobal = "globalvalue" and proceeds to initialize(); At this point
Im using JQuery to setup an onmousedown event on a button on my page
with id="thebutton". When I click the button the alert comes back with
'undefined'. How can I get direct access to my theglobal variable? Code:
View 1 Replies
View Related
Oct 30, 2006
I think I've had JavaScript variable scope figured out, can you please
see if I've got it correctly?
* Variables can be local or global
* When a variable is declared outside any function, it is global
regardless of whether it's declared with or without "var"
* When it is declared inside a function, if declared with "var", it's
local, if not, it's global
* A local variable that is declared inside a function is local to the
whole function, regardless of where it is declared, e.g.:
function blah() {
for(var i ... ) {
var j ...
}}
i and j will both be visible within blah() after their declaration.
* the notion of "function" in this context also applies for this kind
of construct:
var myHandler =
{
onClickDo: function()
{
in the sense that whatever one declares inside onClickDo with "var"
will only be visible inside onClickDo. What else, am I missing anything?
View 4 Replies
View Related
Jan 5, 2007
I've discovered a scenario where Safari 1.3 (I need to make my stuff
compliant with 1.3+) gets confused about the scope of local variables
WITHIN functions that were created in dynamic script blocks. I've made
this example where function def has a local i variable in a loop, and
it calls function abc which also has a local i variable in a loop. What
happens is that Safari is not respecting the scope and is allowing the
called function to corrupt a local variable in the parent function
Here's the whole test page including html tags. If you try it you'll
see that IE and Gecko both produce the output "in abc" twice, because
the def function correctly gets to call abc twice. On Safari, i gets
corrupted, and abc only gets called once... Any ideas what I can do to
prevent this? Code:
View 8 Replies
View Related
Mar 8, 2010
How this can be done in jquery,
Let me explain the question using an example:
<html>
If you run it, the alert messageis "pic2", so jquery sees the entire document, but is there a way to easily restrict it to the sub-tree under the current node (in this case the sub-tree under the span node, since that's what was clicked)? Yes, I can do something like alert($("#div1 img:eq(1)").attr("alt")); //undefined as expected
But I am looking for a solution that's more dynamic, so I don't need to hard code #div1.
View 3 Replies
View Related
Mar 10, 2009
I will do my best to explain this one and sorry if the title isn't that great. I am trying to write a javascript object and it is my first time, so it isn't that great and of course I have trouble.The object is suppose to populate a dropdown (popMake()) and then add an onchange event (checkValue()) to it. It seems to do this fine but when the select box is changed, I no longer have access to object, it's parameters, etc. In checkValue I don't have access to this.currentMake which was just set or anything (already said that).I believe it has something to do with scope (possibly closure, but I didn't see how it would fit her). So how can I do something like this and still have access to the object after the click?Code below:Code:
window.onload = function() {
var mm = new makeModel();
mm.popMake();
[code]....
View 6 Replies
View Related
Aug 19, 2006
In my UI framework, I have an event handler - just like many frameworks do. My handler is a static object, and contains methods to take care of things like mouse events, etc. However, upon adding a method to handle onfocus today, I ran into a very odd problem in Firefox. I've put together an example page that generates the error:
View 14 Replies
View Related
Jun 14, 2010
I've created a jQuery script that uses a switch statement. However, my experience with it, relative to variable scope, doesn't seem to follow the logic.According to the JavaScript/jQuery theory, a global variable was accessible (meaning read & write) throughtout any function within any script (one that page).However, apparently that theory wasn't completely true as it pertained to switch statements that contained variables. To illustrate my case in point, I've included a simplistic version of my code:
$("#selector").delegate("div", "click", function(event) {
var testVar = 4;
switch (this.id) {
[code]...
As shown, the variable "testVar" is not accessible from one case to the next case .Furthermore, to add insult to injury, I am seeing the same behavior within the conditional if else statement counterpart to the switch statement.
View 1 Replies
View Related
Aug 11, 2004
Here's the situation: I have a javascript object for controlling a custom DHTML scrollbar. So that I can use more than one on a page, the event listeners need to be passed a reference to the particular instance of the object that each needs to connect to, but as I discovered the hard way, inside an event listener, 'this' returns a reference to the DOM object throwing the event, rather than to the JS object. Short of coming up with a linked list of different objects and having the event handler search through it for the right object when an event is generated, then writing a reference to that object to some global variable, is there any convenient way to tie this together? I hope I've made myself clear enough...
View 5 Replies
View Related
Mar 26, 2006
I'm having trouble getting the following code to work properly. Every time I try to access the private testing variable from the priveleged MyMethod it gives an error. Says it can't find testing and that it has no properties so I can't run a push() command on it.
function MyClass()
{
var testing = new Array();
// define the method
function MyMethod()
{
this.testing.push("hello");
}
// make the method priveledged
this.MyMethod = MyMethod;
}
// a test function it ensure the variables declared here are isolated
function Start()
{
var myClass = new MyClass();
myClass.MyMethod();
document.write("[" + myClass.testing + "]");
}
Start();
View 3 Replies
View Related
Dec 13, 2011
i'm having a slight problem understand how to use this.myVar in an object. And I use prototype.
[Code]...
Does anyone know how I can use this.myvar within the function. I have tried binding and bindAsEventListener.But nothing I've done has been able to get the right value!
View 2 Replies
View Related