Jump to content

Passing through information to PHP by clicking div.


madmenyo

Recommended Posts

Hi folks,

 

I try to keep my explanation as short as possible.

 

I have a page that loads a php script on opening with all the cards in my database. When a player clicks a div of a specific card div a popup comes up asking if he wants to add this card to his collection. When choosing yes the specific card goes into his private collection.

 

Problem is, the card div has already got an ID for layout purpose. Can i give this div somekind of extra info while generating them from my PHP script. And then sent that info back to the PHP script that should add the card to the players DB.

 

I am using Jquery to sent and receive data from my php script something like this.

 

<script>
$(document).ready(function(){
    $('#halfrow').click(function(){ //<-- the div that gets clicked
        $('#popuplarge').css({'visibilty':'visible'}) //<-- the popup
	$.post( 
        "addcard.php",
        { cardID: $("#cardDiv").val()}, //<--- here i sent the info to the php script so the correct card can be added.
        function(data) {
        $("#popuplarge").html(data);
        });
});
});
</script>

 

Is there a way to add a hidden <input /> with the card ID div and then sent that trough with Jquery? Still the same problem here as all the divs have the same ID and the jquery script would not know witch hidden <input /> to sent.

 

I could also make the whole div a button but thats probably not desirable for layout purpose.

 

I can always add a button to the div wich has to be clicked. But i would really like the user can click anywhere on the div. And i rather not want to redesign the div :D.

As always a couple of minutes after my post i fix things :D. Please ignore all my future posts.... :D

 

I was able to give the card DIV a title and sent that with Jquery through this line:

 

$.post(

        "recruitcode.php",

        { cardID: $(this).attr("title")}

 

Now i can generate all these divs and give them the correct title. Then when i click 'm i can sent the correct information to the script that adds them to the players private DB.

 

Anyways, if you know of other ways i'd really like to know as title allows you to sent only 1 variable. Fortunately i only need just 1.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.