Send Var through html(data)

Discussion in 'Javascript' started by GREFF1978, Feb 29, 2020.

  1. GREFF1978

    GREFF1978

    Joined:
    Feb 29, 2020
    Messages:
    1
    Likes Received:
    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 (Text):

    <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>
     
     
    GREFF1978, Feb 29, 2020
    #1
    1. Advertisements

  2. GREFF1978

    hacxx

    Joined:
    Feb 19, 2020
    Messages:
    12
    Likes Received:
    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 :/
     
    hacxx, Feb 29, 2020
    #2
    1. Advertisements

  3. GREFF1978

    sunfighter

    Joined:
    Nov 27, 2019
    Messages:
    82
    Likes Received:
    10
    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'.
     
    sunfighter, Feb 29, 2020
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...