CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   Multiple Classes with same ID (http://www.codingforums.com/showthread.php?t=248640)

dwatson251 01-12-2012 01:38 PM

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; 
                });
        });                               
});



All times are GMT +1. The time now is 12:34 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.