0

I have a button that uploads the excel file.

<input type="file" id="input-excel" value="Choose File" accept=".xlsx" />

Below is an embedded script in the HTML to read the excel file and display it in the UI.

<script type="text/javascript">
    
   // read and display the records from excel file on the screen
   
    // passing in my button id here
    $('#input-excel').change(function (e) {
        var reader = new FileReader();
        reader.readAsArrayBuffer(e.target.files[0]);

        reader.onload = function (e) {
            var excelData = new Uint8Array(reader.result);
            var wb = XLSX.read(excelData, { type: 'array' });
            console.log(wb);

            var htmlstr = XLSX.write(wb, {/* sheet: "Sheet1",*/ type: 'binary', bookType: 'html'});
            $('#wrapper')[0].innerHTML += htmlstr;
        };
    });
</script>

@section scripts{

    <script src="~/Scripts/ViewModels/RmaCreation/rmacreation.js"></script>
    <script src="~/Scripts/knockout-3.2.0.js"></script>
    <script language="javascript" src="~/Scripts/xlsx.full.min.js"></script>

}

I am able to upload excel file in the first iteration. I can see the records from the excel file in the UI.

However, the button becomes unresponsive in the second iteration. How do I make this button responsive after every iteration?

0

1 Answer 1

1

https://jsfiddle.net/03ut9zjs/2/

<input type="file" id="input-excel" value="Choose File" accept=".xlsx" />

<div id="wrapper">

</div>

    
   // read and display the records from excel file on the screen
   
    // passing in my button id here
    $('#input-excel').change(function (e) {
        $('#wrapper')[0].innerHTML ="";
        var reader = new FileReader();
        reader.readAsArrayBuffer(e.target.files[0]);
        reader.onload = function (e) {
            var excelData = new Uint8Array(reader.result);
            var wb = XLSX.read(excelData, { type: 'array' });
            console.log(wb);

            var htmlstr = XLSX.write(wb, {/* sheet: "Sheet1",*/ type: 'binary', bookType: 'html'});
            $('#wrapper')[0].innerHTML += htmlstr;
        };
    });


You haven't included wrapper div in your code so i am not sure where/how you've placed it.

It seems to work fine in this fiddle. Are you able to recreate the issue here?

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. The wrapper div was placed in the wrong place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.