[js/jquery] variables

Joined
Sep 10, 2006
Messages
2,811
Reaction score
1,417
PHP:
$.global = {
    dayBox_0: ""
}

function addInput(dayWrap) {
    $("."+dayWrap+" .menuText.last").keyup(function() {
        
        alert($.global.dayWrap);
    

    });
    
}

$(document).ready(function(){
    addInput('dayBox_0');
});

You should see what's I want to archieve from the code anyway,

this way it takes $.global.dayWrap "dayWrap" as just another variables that should've been defined in my $.global namespace, but I need it to consider "dayWrap" as the variables defined in function, thus becaming $.global.dayBox_0.. Any idea how to do that?
 
PHP:
$.global = {
    dayBox_0: ""
}

function addInput(dayWrap) {
    if( !(dayWrap instanceof String) && !(typeof(dayWrap)=="string") )return;
    $("."+dayWrap+" .menuText.last").keyup(function() {
        alert($.global[dayWrap]);
    });
    
}

$(document).ready(function(){
    addInput('dayBox_0');
});

Properties of objects can be accessed using [] as if the object is an associative array.
 
Last edited:
Thanks, sadly I found more sufficient way of doing what I wanted to accomplish with this, so I don't need it. But hey, at least I learned something new.

---------- Post added at 09:42 PM ---------- Previous post was at 08:40 PM ----------

[nomedia]http://www.youtube.com/watch?v=pBB8JVoVXqs&fmt=22[/nomedia]

I never thought making such a thing would be that big pain in the ass..

I guess I could be done somewhat smoother, but at least it works.

PHP:
function removeLine(dayWrap) {
	$('.removeLine').click(function() {
	
		$('.locked:last').removeClass('locked');
		var prev = $(this).parent().prev();
		prev.find('.menuText').addClass('last');
		
		$(this).parent().fadeOut('fast', function() { 
			$(this).remove(); 			
			var countWraps = $("."+dayWrap).size();

			if(countWraps != "1") {			
				prev.append('<a href="#" class="removeLine">[X]</a>'); 
				removeLine(dayWrap); 
			}

		});
		
	});
}
function addInput(dayWrap) {
	$("."+dayWrap+" .menuText.last").keyup(function() {
	
		if(!$(this).is('.locked')) {
			var element = $(this).parent();
			var wrapper = element.parent();
			var clone = element.clone();
			
			$(":input", clone).val("");
			
			wrapper.append(clone);		
			$(".removeLine").remove();
			clone.append('<a href="#" class="removeLine">[X]</a>');

			$(this).removeClass('last');
			$(this).addClass('locked');
			
			addInput(dayWrap);	
			removeLine(dayWrap);			
		}

	});
	
}

$(document).ready(function(){
	addInput('dayBox_0');
	addInput('dayBox_1');
	addInput('dayBox_2');
	addInput('dayBox_3');
	addInput('dayBox_4');
	addInput('dayBox_5');
	addInput('dayBox_6');		
});
 
Last edited:
Back