When I down load a file using a csp page, the application  shows  the percentage as  37 %, 74 %, and 100 %.    I am trying to make changes to the application that it shows one percentage after each read.  The first time it reads, it would display 37%.   The next run would replace

37 %  with 74 % and so on until it completes its download.   I have tried adding javascript code to the application  however it doesn't work.   For example when I enter &js('alert');, the application displays it value on the screen.  Also, I tryed putting it between two scripts tags and it doesn't work.

I can use html however I cannot update the line after it displays information.   Does anybody know how I can use javascript code with cache method?   

Below is my code:

 

<form enctype="multipart/form-data" method="post" action="upload20180615.csp">
    Enter a file to upload here: <input type=file size=30 name=FileStream>
    <hr />
    <ul><input type="submit" value="Upload file"></ul>
     
</form>

<csp:if condition='($data(%request.MimeData("FileStream",1)))'>
    <h2>Saving file...</h2>
    <h0 style="background-color:MediumSeaGreen;">Process status: </h0>
    
    <script language="Cache" runat="server">
        Set data=%request.MimeData("FileStream",1)
        Set stream=##class(%FileBinaryStream).%New()
        Set D=%request.MimeData("FileStream",1).FileName ;selected file
        Set Size=%request.MimeData("FileStream",1).Size 
           
        ;Set file=##class(%File).%New(D)
                
        L="" I=1:1:10 T=$P(D,"\",I) T=""  L=Q        
        FILE=$P(D,"\",L-1)
                
        DIR="F:\a misc\"
        ;
        FILENAM=$E(FILE,1,$L(FILE)-4)
        FILENAM=$ZSTRIP(FILENAM,"<>","W")
        
        DIR=DIR_FILENAM
        X=$ZF(-1,"MKDIR """_DIR_"""")
        DIR=DIR_"\"
        ;retrieve the file and place in the new placeo
                
        Do stream.LinkToFile(DIR_FILE)
                        
        Set RTotal = 0
        While (data.AtEnd'=1) {
        Set len=32000
         Set x=data.Read(.len)
         Set RTotal=RTotal+len
         Set Percent = ((RTotal / Size) * 100) \ 1
         Do stream.Write(x)
         ;Write "<h>"_Percent_" % </h>"
          d=Percent s:$l(d)=2 d=" "_d=d_" %"
           
           ;Write "<h style=background-color:rgb(60,179,113);>"_Percent_" % </h>"
           ;&js< alert('hi') >
            &html<
                >
            &html< <h>#(d)#</h> >
        }

Set Status = stream.SaveStream()
        If (Status = 1) {
            Write "

Uploaded!

"            
        }
        Else {
            Write "

Saving failed!

"

        }
             
}
        
    </script>
</csp:if>
</body>
</html>