Validating A Stringified Scope Chain?
Feb 9, 2009Let's say I have the string "Bob.underwear.drawer.sortBy" which would be the Scope Chain Required to access an object similar to this:
Code:
var Bob = {
underwear: {
[code].....
Let's say I have the string "Bob.underwear.drawer.sortBy" which would be the Scope Chain Required to access an object similar to this:
Code:
var Bob = {
underwear: {
[code].....
Why my email field is validating, but mycode for validating empty fields is not?
View 1 Replies View RelatedI am using a validating form plug in for jquery and I have a question about it. Let this function will be an ex.:
[Code]....
'e' is the name attribute of one form element, but can I choose more elements using jquery (CSS) rules like this: input[name*=e] or how can I do something similar?
Is there any chances some one teach me how to do this... in jquery ?
View 2 Replies View RelatedI'm trying to have an effect happen after an effect for some other elements has finished.
$(document).ready(function() {
$("#about_div").toggle(function() {
$(".work_divs").slideUp(600);
[code]....
and a couple of variations. I increased the duration to slow it down but the effects occur simultaneously.
On change of the first drop down i want another drop down list to get populate with optgroup in it
View 1 Replies View RelatedI want to try and keep my syntax all encapsulted, but I'm not sure how to go about this.
So I add in some html to a div
$('#slideStage').append("<div id='popupTiming' style='display:none'>" + formatTime(currentCuePoint.time) + ' minutes</div>')
So the resulting html would be
[Code]...
I have a list oF div embedded into one
<div id="main">
<div>item 1</div>
<div>item 2</div>
[code]....
I'm sure a Google search could answer this, but I don't know what it's called, haha. Dot sytax maybe?chain methodsHow do I write a function that can be called like this:
$('p').myFunction().val('the new value');
I played around, tried this:
function myFunction() {
$(this).css({'color': 'red'});
}
[code]....
I've checked Google and searched the jQuery forum and didn't see anything. Is there a way to do the following as I'd like to use the same chain multiple times with with different selectors:
var chain = .attr('value', 'Search Digital Collections').css('color', '#E0E0E0');
An example:
tabContent.css('width', '0')
.css('opacity', '0')
.filter(':eq(0)')
.css('opacity', '1')
.parent()
.find('.one-tab')
.addClass('active')
.css('cursor', 'default');
Now I want to apply the parent of tabContent a width, only if a condition is true. I do this, and works, but I don't consider this is a proper way:
tabContent.css('width', '0')
.css('opacity', '0')
.filter(':eq(0)')
.css('opacity', '1')
.parent()
.each(function() {
if (/*condition is true*/) {
$(this).width(aWidth + 'px');
}
$(this).find('.one-tab')
.addClass('active')
.css('cursor', 'default');
});
Is there a better way instead of using each() which is actually made for loops? In this case there is only one element.
I'm trying to incorporateRemy's select-chainplug-in into my code, and I'm having troubles. I hopesomeone can take a minute or two to help me. My situationseemed simple, only 2 levels, Products and Programs under each Product. I have the back-end working, so it returns the JSON list of Programswhena Product ID is passed. However, the plug-in keeps failing in the .ajax() function, tripping the error(). It reports a "parsererror", so I know I've messed up something. One wrinkle, I have multiples of the Product/Program pairs on my page, identified as "prod_x"/"prog_x", so I need to dynamically call them. Here is my code:
[Code]...
I'm trying to combine a chained drop down list with the ability for the last selection to show/hide a div. I've researched and found ways to do both individually, but I'm hitting the wall when it comes to combining the javascript.
This is how I'd like it to work:
-- User selects from DropDown List 1.
-- DropDown List 2 options appear based on the selection in 1.
-- User selects from DropDown List 2,
-- Appropriate div is shown.
Here's the Javascript I'm using to show/hide a div:
function showDiv(divID)
{
var div = document.getElementById(divID);
div.style.display = ""; //display div
}
[Code]....
Is it possible with AJAX chained selects to have one select box on the page and then have another select box appear depending on the selection from the first select box?[URL]Is it possible to hide the 2nd box until the first one was acted upon?
My goal is to start with one box (call it Box 1). Box 2 will then appear. Depending on Box 2's input, Box 3 will appear with new choices. Depending on Box 3's input, Box 4 will appear....so on and so forth until the end goal is met.
When additional boxes appear, I do not want the previous boxes to disappear. If PHP can populate the select boxes, I don't see why it also couldn't insert the physical select box.
How to pass data down to chain calls of deferred object? code...
View 1 Replies View RelatedI created a dropdown menu using jquery. So when I hover over a button it slides down the menu. Now if I move the mouse out of the menu and bring it back in before it slides up(menu has a lot of items so there is enough time to bring the mouse back in on the menu)over the dropdown menu it starts a chain of slideDown() and slideUp() functions and it does not stop till I move the mouse of the menu or back on the button. Below is my jquery code:
[Code]...
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]...
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.
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?
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
}
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?
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?
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.
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 RelatedI'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);
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: