[jQuery] Variable Scope Help

2009-08-27 Thread WhoButSB

Hello All,

I'm running into some issues where I'm alittle confused about the
scope of my variables.

I have this code:

$(function(){

var categoryID;

 //Aloha Item Category Dropdown Selection
//Takes the Selected Value and adds it to Item Search Ending
$("#add-item select[name='CategoryId']").change(function(){
categoryID = $("#add-item select[name='CategoryId'] 
:selected").val
();
return categoryID;
});

//Item Search for food name
$("#add-item #ITEMNAME").autocomplete("/"+categoryID, {
selectFirst: false,
formatItem: formatItem,
formatResult: formatResult
}).result(function(row, item, data) {
$('#add-item #ITEMNAME').val(item[0]);
$('#add-item #ITEMID').val(item[1]);
});
}



What I'm trying to do is take a selection value from a drop down menu
and append the value to the end of the URL in the auocomplete plugin.
For some reason I'am not able to get this to work.  Whenever I view
the AJAX request it says that the value is undefined.  But if I put a
console.log() into where I select the value it comes up correctly.  I
believe its the way i'm defining the vairables scope.  THank you for
the help!


[jQuery] variable scope

2009-08-23 Thread mrtedweb

Hello everyone,

I'm new to jQuery and need some help with a trivial question. I'm
trying to program a menu bar and I'm having problems with variable
scope. Below is a snippet of my code:

//
**

$(document).ready(function()
{
var menubar = new MenuBar();
});



function MenuBar()
{
this.currentIndex = 0;
$('.menu_button').click(this.onClick);
};

MenuBar.prototype.onClick = function(evt)
{
this.currentIndex = 1;   //<--Unable to access class variable!!
this.Select(this.currentIndex);  //<--Unable to access class
funtion!!
};

MenuBar.prototype.Select = function(index)
{
//code goes here
};

//
**

Once the onClick event is received the scope move from the class to
the actual item itself. How do I access class variables amd functions
after receiving an event??

Any help is greatly appreciated.

-Ted


[jQuery] Variable scope trouble

2009-07-18 Thread rhodopsin

I am attempting to use the return value from a nested ajax function as
the value for a variable in its parent. However, despite being able to
successfully assign the variable within the nested function, it
reverts back to its original value after the child function has
terminated. Below is the code:

$('a[href^=logmar]').tooltip({
bodyHandler: function() {
var args = $(this).attr("href").split('?')[1];
var lm_out = "test";
// <--
attempting to set lm_out
if(args.charAt(0) == "l")
{
var lm = args.substring(2, args.length);
$.get("templates/templates.php",
{'action': 'lm2sn', 'l' : lm },
function(response){
if(response.length > 0)
{
lm_out = response;
alert(lm_out);  
// <-- no problem here
}
});
}
return lm_out;  
 //
<-- value has returned to "test"
},
showURL: false
});

Any suggestions on how to tackle would be most welcome. I have read so
much about scope and closure tonight that my eyes are bleary!

Thanks,
Rick


[jQuery] Variable scope

2009-06-28 Thread DanielMedia

Hi,

I'm pretty new to jQuery. I'm having a problem with variable scope.
This function always returns false. The success variable is not being
changed within the getJSON function. I'd appreciate any help. Thanks.

var check_user = function() {
var success = false;
url = baseurl + '/ajax/check_user_auth';
$.getJSON(url, function(response)   {
if(response.ok) {
alert(response.ok); // (evaluates to true)
success = true; // The parent "success" variable 
doesn't change.
This function always returns false.
}
});
return success;
}


[jQuery] variable scope bug in Firefox only?

2008-12-28 Thread Liam Morley

I'm experiencing an issue in Firefox 3 where, if a variable is
declared locally, it doesn't return expected results. I've tried the
same thing in IE7 and Chrome, I don't experience the bug in those
browsers.

My particular example is as follows:

var children = $("ul.cat_container > li.column:not(.pinned):first");
if (children.length > 0) {
...
} else {
...
}

In *Firefox only*, children.length will never be greater than 0,
unless children is declared globally (without 'var').

Has anyone else run up against this? Is this a Firefox issue, or a
jquery issue? (Or potentially a problem with my code? In which case,
why would I have different behavior in only one browser...)


[jQuery] Variable scope: Newbie Question

2008-12-05 Thread Mat

Hi there,

I'm sorry this is a pretty newbie question


I am using JQuery with an xml file and autocomplete. What I am trying
to achieve is to use an xml file as my data source to autocomplete
cities in a form once a user selects their province. When a user
selects a particular province then only the cities in that province
will be listed by the autocomplete script as the user starts to type
in the 'city' form field.

My problem here is that I am trying to use the array 'towncity' as my
data source for autocomplete and change the contents of the array when
the province select box #province is changed. However, I can not get
my $('#province').change(function() to affect the array 'towncity'
that I have declared outside of the function


$(document).ready(function() {
var towncity = window.towncity = new Array();
$("#city").autocomplete(towncity);
$.preloadCssImages();
$('div.jshide').show();
$("#tenantForm").validate({
  rules: {
name: {
  required: true,
  minlength: 2
},
province:"required",
ccom:"required",
occupied: "required",
rented:"required",
condo:"required",
payment:"required"

  }
});


$("#renewdate").datepicker({
dateFormat: "d M, yy",
showOn: "both",
buttonImage: "images/calendar.gif",
buttonImageOnly: true
});

$('#province').change(function() {
var currprov = $('option:selected', this).text();

$(function() {
$.ajax({
type: "GET",
url: "xml/location.xml",
dataType: "xml",
success: function(xml) {

$(xml).find("[EMAIL 
PROTECTED]'"+ currprov +"'] >
TOWN_CITY_NAME").each(function(){
towncity = 
$(this).text();
});
}
});
});
});
});



Anyone have any ideas?

Thanks,
Mat


[jQuery] Variable Scope

2008-10-08 Thread QuickScriptz

So I've been over my code again and again and I've scoured through the
Wiki and Help Documentation but I still cannot seem to make it work. I
have a row of icons and the idea is when you mouseover, a popup ()
appears below it and then when you mouseout, it fades again.

I've found the best way to do it is that start with all the popups to
the side of the icons (so you can still hover over the icons and the
popups don't just block your way) and the popups begin as hidden
(opacity: 0). When you mouseover the icons, it sets the "top" and
"left" attribute of the popup to just below the icon and then it
slowly fades the popup from 0 to .7 and then vice versa when mouseout.

So, here is my code. You can view the product at the site below. Any
suggestions?
http://dev.quickscriptz.ca/v4/index.php

 //