jQuery submits via post, but how do I get the content of my DIV


WEBGONDEL UG

I have many div elements (with football players on them)

I want to implement a submit button and send all players from my field to my MySQL database.

How can I get the value (ID and other attributes of other clicked elements, which were clicked before)

Here is a fiddle, the fields look like https://jsfiddle.net/qcvcga8k/47/

Simple structure

<div Id="123">
Content
</div>

thank you for your help;)

greeting

cod

I'm not really sure if I really understand you, but if you want to get the contents of several divs that select them via the ID attribute, and then post it with the ajax request, you can use the following code:

var ids = ['123', '234', '345', '545', ...];
$('#yourSubmitButton').on('click', function(){

    var postData = {};
    ids.each(function(i, oneId){

        postData[oneId] = $('#' + oneId).html(); 
        // you can either use:
        // $('#' + oneId)[0].innerHTML or
        // document.getElementById(oneId).innerHTML   
    }); 

    $.ajax({
        method: 'post',
        url: 'url.that.will.process.the.data',
        data: postData,
        success: function(response){
            console.log(response);    
        } ,
        error: function(err){
            consolg.log(err);
        }
    });
});

Related


How to get div content via jQuery?

Motevalizadeh I have developed a sample in which I have a list @foreach (var pin in Model.myList) { <div> @Html.Hidden("idx", @pin.Id) <div><span>@pin.Content</span></div> </div> } and wrote the html result is: <div

How to get div content via jQuery?

Motevalizadeh I have developed a sample in which I have a list @foreach (var pin in Model.myList) { <div> @Html.Hidden("idx", @pin.Id) <div><span>@pin.Content</span></div> </div> } and wrote the html result is: <div

How do I get the content of this div right?

Steve Gates I'm trying to improve my basic design "skills". I'm trying to recreate it: but I don't know how to format it properly with the correct CSS. .container { width: 40%; height: 107px; background: #fff; position: relative; } .cover {

How do I get the content of this div right?

Steve Gates I'm trying to improve my basic design "skills". I'm trying to recreate it: but I don't know how to format it properly with the correct CSS. .container { width: 40%; height: 107px; background: #fff; position: relative; } .cover {

How do I get the content of this div right?

Steve Gates I'm trying to improve my basic design "skills". I'm trying to recreate it: but I don't know how to format it properly with the correct CSS. .container { width: 40%; height: 107px; background: #fff; position: relative; } .cover {

How do I get my $_Post to work

turquoise I'm trying to get my site to submit an email every time someone sends a message (now I'm struggling to get variables to work...). It's a learning process, so I'm giving it my all here, just trying to teach myself. But don't like global php commands $

How do I post and upload content via email?

username I have a website and would like to be able to post content via email, like in many large social networks. (eg Facebook, Flickr) Like: I will send a message to "[email protected]" and the headers will be saved to the MySQL database and the attachments wi

How do I post and upload content via email?

username I have a website and would like to be able to post content via email, like in many large social networks. (eg Facebook, Flickr) Like: I will send a message to "[email protected]" and the header will be saved to the MySQL database and the attachment will

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

How do I get my dropdown div positioned in the correct position?

Mel When I click on my divs, I want them all to be in the same position, i.e. to the right and below the div content, but they are in the same position as the div I clicked on, as if they were all on top of each other A small box, if that makes sense. I'm not

How do I get my dropdown div positioned in the correct position?

Mel When I click on my divs, I want them all to be in the same position i.e. to the right and below the div content, but they are in the same position as the div I clicked on, as if they were all on top of each other A small box, if that makes sense. I'm not e

How do I get my jQuery code to work on all elements

Brown I have this accordion menu but it only works on the first menu ul. How can I make it work in all ulsuch environments ? I know it would be great in the future if you could explain what I'm doing wrong. Also, how do I get the link to switch between the two

How do I get my nested if statement to work in jQuery

user3298548 Right now there is an input text box where users type in a word. Once they type in that word and press enter, the word disappears and a new one appears and so on. If they type it wrong the color turns red. I can only get it to work once however bec

How do I get my jQuery code to work on all elements

Brown I have this accordion menu but it only works on the first menu ul. How can I make it work in all ulsuch environments ? I know it would be great in the future if you could explain what I'm doing wrong. Also, how do I get the link to switch between the two

How to get height of div container via jQuery?

Raguraman I'm developing an "Author Pages" section for a book publishing website and use the "Show More/Show Less" button. There are two media divs, one for the author image (on the left) and one for its abstract (on the right). I want to enable/disable the "S

How to get height of div container via jQuery?

Raguraman I'm developing an "Author Pages" section for a book publishing website and use the "Show More/Show Less" button. There are two media divs, one for the author image (on the left) and one for its abstract (on the right). I want to enable/disable the "S

How to get height of div container via jQuery?

Raguraman I'm developing an "Author Pages" section for a book publishing website and use the "Show More/Show Less" button. There are two media divs, one for the author image (left) and one for the abstract (right). I want to enable/disable the "Show More/Show

How to get height of div container via jQuery?

Raguraman I'm developing an "Author Pages" section for a book publishing website and use the "Show More/Show Less" button. There are two media divs, one for the author image (left) and one for the abstract (right). I want to enable/disable the "Show More/Show

How do I update the content in my database?

Dulwich I'm trying to update a value I get from the database, but it doesn't seem to go to the routing function I tried changing the routing method and even stopping the request but it doesn't seem to work this is the route Route::put("/users/bonus/update/{id}

How do I update the content in my database?

Dulwich I'm trying to update a value I get from the database, but it doesn't seem to go to the routing function I tried changing the routing method and even stopping the request but it doesn't seem to work this is the route Route::put("/users/bonus/update/{id}

How to get the content of a file sent via POST in Laravel 4?

Russian Rosary I have a form that sends a text file via POST method in Laravel 4. However, inside the Controller, I can't figure out how to get its content so I can put it into a BLOB field in the database. Laravel's documentation and all the posts I've found

How do I toggle the post content in the "Post" header of a page?

Shob Mirza I'm trying to serve all "post" titles in a specific page. So if someone clicks on the post, its content has to toggle below the header, and if someone clicks on the header again, the content has to hide. I solved half the problem with the help of th