Send Var through html(data)

Joined
Feb 29, 2020
Messages
1
Reaction score
0
Howdy!

I'm still learning a fair bit, and I've done a lot of searching and just cannot find an answer to something that is probably very simple...

I need the id of #itemChange to match the itemID variable.. so if itemID = 20 then I need the html output to send to id #itemChange-20 - however, I am unsure how to add this variable into the .html(data) line. What I have done obviously does not work.

Any help appreciated :)

Code:
<script>
 $(".ajaxSwitchItem").click(function () {
    var itemID = $(this).attr("data");
     $.ajax({
        url: "ajax/php/itemChange.php",
        data:'itemID='+itemID,
        success: function(data){
            $('#itemChange-'+teamID).html(data);
        }
    });
});
</script>
 
Joined
Feb 19, 2020
Messages
22
Reaction score
0
I normally use id= in the form i want to var and then

var field_id = document.getElementById('field_id').value;

And use the var like "+field_id+" on the code, in your case ajax request.

Might not be what you are looking for :/
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
You say you are learning. My advice is to stop playing with frameworks and learn the real thing JAVASCRIPT.
Jquery always carries baggage that bloats your program. JS is just as easy to learn and use.

Next JS without the HTML that it works with adds to the work trying to help. So a little of the HTML code always helps.

Lastly
$('#itemChange-'+teamID).html(data);
you have never declared 'teamID' anywhere, I think it S/B 'itemID'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top