Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-25-2012, 12:41 PM   PM User | #1
grandpajim
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
grandpajim is an unknown quantity at this point
need help with selection

Hi, I'm new to jquery, please bear with me. I created a page from code i found online. I have 2 divs, 1 with data from mysql, the other is empty. I can make a selection by clicking a checkbox, which each line has one, and then click a button and move all checked items to bottom div. I want to check all the items I've moved to the bottom div and post them to a processing page, but this is where it gets weird. let's say I check 3 lines, any 3, and move them down the first 3 in the top div are what's sent to the process page. This is the code I'm using.
Code:
$(document).ready(function () {
		// Uncheck each checkbox on body load
		$('#batch_content .selectit').each(function() {this.checked = false;});
		$('#lower_batchwin .selectit').each(function() {this.checked = false;});
		
    	$('#batch_content .selectit').click(function() {
			var userid = $(this).val();
			$('#user' + userid).toggleClass('innertxt_bg');
		});
		
		$('#lower_batchwin .selectit').click(function() {
			var userid = $(this).val();
			$('#user' + userid).toggleClass('innertxt_bg');
		});
		
		$("#move_down").click(function() {
			var users = $('#lower_batchwin .innertxt2').size();
			var lower_batchwin = $('#batch_content .innertxt_bg').size();
			
		//	if (users + lower_batchwin > 5) {
		//		alert('You can only chose maximum 5 users.');
		//		return;
		//	}
			
			$('#batch_content .innertxt_bg').each(function() {
				var user_id = $(this).attr('userid');
				$('#select' + user_id).each(function() {this.checked = false;});
				
				var user_clone = $(this).clone(true);
				$(user_clone).removeClass('innertxt');
				$(user_clone).removeClass('innertxt_bg');
				$(user_clone).addClass('innertxt2');
				
				$('#lower_batchwin').prepend(user_clone);
				$(this).remove();
			});
		});
		
		$("#move_up").click(function() {
			$('#lower_batchwin .innertxt_bg').each(function() {
				var user_id = $(this).attr('userid');
				$('#select' + user_id).each(function() {this.checked = false;});
				
				var user_clone = $(this).clone(true);
				$(user_clone).removeClass('innertxt2');
				$(user_clone).removeClass('innertxt_bg');
				$(user_clone).addClass('innertxt');
				
				$('#batch_content').append(user_clone);
				$(this).remove();
			});
		});
		
		$('#view').click(function() {
			var users = '';
			$('#lower_batchwin .innertxt2').each(function() {
				var user_id = $(this).attr('userid');
				if (users == '') 
					users += user_id;
				else
					users += ',' + user_id;
			});
			alert(users);
		});
	});
grandpajim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:47 PM.


Advertisement
Log in to turn off these ads.