Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

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 01-12-2012, 01:38 PM   PM User | #1
dwatson251
New to the CF scene

 
Join Date: Jan 2012
Location: Nottingham, England, United Kingdom
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dwatson251 is an unknown quantity at this point
Multiple Classes with same ID

Here's my site: http://dabrix.zxq.net/

I want it so when you click the pencil icon (Whilst logged in) a text area shows up instead of the content, and clicking submit when changing the information, we update the DB.

To display each block I'm running a while loop in PHP so each block uses the same class, but for Jquery I need to somehow identify each block so I can link the pencil button thing to each block.

At the moment I'm using the :eq() suffix at the end of the selector to do so, but it seems the more I press the edit icon in the first block, the other blocks get edited and I'm not sure what the problem is.

Code:
$(document).ready(function() {
	var blockdata = $('.blockdata:eq(0)').html();
	$(".edit:eq(0)").click(function() {
		$(".updateblock:eq(0)").show();
		$(".blockdata:eq(0)").hide();
		$("form.updateblock:eq(0)").submit(function() { 
			var newblockdata = $('.newblockdata:eq(0)').attr('value'); 
			var newblockcolor = $('.newblockcolor:eq(0)').attr('value');
			$.ajax({  
				type: "POST",  
				url: "edit.php",  
				data: "block=" + newblockdata + "& color=" + newblockcolor,  
				success: function(){ 
					alert("Success");
					$('.blockdata:eq(0)').replaceWith(newblockdata);
					$('.block:eq(0)').css("background-color", newblockcolor);
					$(".updateblock:eq(0)").hide();
					$(".blockdata:eq(0)").show();
				}  
			});  
		return false;  
		}); 
	});				
});
dwatson251 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 01:09 PM.


Advertisement
Log in to turn off these ads.