skip to Main Content

I am trying to change the content of div "info" using the script as shown below

I am trying to change the content of div "info" using the script as shown below
Code

But We can see that the content of the div is changing in the inspected screen and Not reflecting in the browser screen.

enter image description here

Please help me to fix this issue.

function GeneratePaySlips() {
    ShowLoaderOnElement(".btn-generate");
    if ($("#driverIDs").val().length > 0) {
        var i = 0;
        var driverIDs = $("#driverIDs").val().split(',');
        //for (var i = 0; i < driverIDs.length; i++)
        for (i = 0; i < 5; i++) {
            document.getElementById("info").innerHTML = i + 1 + ' of ' + $("#totalDrivers").val();
            $.ajax({
                type: "POST",
                data: { "driverID": driverIDs[i] },
                async: false,
                cache: false,
                url: '/BulkPaySlip/GeneratePaySlip',
                success: function (response) {
                    if (response.isSuccess) {
                    }
                    else {
                    }
                },
                error: function (response) {
                    HideLoaderOnElement(".btn-generate");
                },
                complete: function () {

                }
            });
        }
        if (i >= driverIDs.length) {
            HideLoaderOnElement(".btn-generate");
        }
    }
}

2

Answers


  1. So I can’t see all the code but maybe put the code in a < script > tag right before the html element and then see what happens.

    Login or Signup to reply.
  2. First of all innnerHTML is used to change the content of the specified element you called. On your above codes, the contents will go to the div element without creating any elements tags thus not displaying the content you wanted.
    The below code can work if you need to create another element on DIV tag

    .innerHTML = '<p>' + $('#totalDrivers').value + '</p>
    

    or you can try and create a new element which you can later append to the div five times according to your for loop. Run the code below

    for (var i = 0; i < 5; i++) {
        var element = document.createElement('p')
        var text = $('#totalDrivers').value /* You can use strings to show the result fast // var text = 'i am coming' // */
        element.textContent = text
        document.getElementById('text').appendChild(element)
    }
    

    The codes are self-explanatory, sorry for mentioning this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search