Function Outputs an error message
Example S10ErrorMessage(f, msg);

Parameters
Nr Description
1
Anchor object
2
Error message (HTML format)
3 Explanation of the error (HTML format)
Description  The specified message is output below the specified anchor object.
 
If the HTML file contains a separate message line 

<div class="messagearea"></div>

the output is not in the form of a pop-up, but in this message line. If you have specified an explanation as the third parameter, the output is always a pop-up.

Both the message and the explanation are interpreted as HTML text, so you can use any HTML formatting.

HTML and JavaScript code for the example above:

<button type="button" class="button"  onclick="upload_image(this, 'file_input')">
    Upload
</button>
<input type="file" id="file_input" style="width:400px" accept="image/*" />


<script>
 function upload_image(f, id) {

   
// <input> element
   
var h = document.getElementById(id);

    if (h.files.length == 0) return;

    if (h.files[0].size > 4*1024*1024) {
       var msg = "Image file too large; the maximum size is 4MB."
               +
"<br><br>"
               +
"Your file has the size  "
               + stringFileSize(h.files[0].size);

        S10ErrorMessage(f, msg);

    };

    <!– upload
image -->             
    …

 }

 
function stringFileSize(number) {
   if (number < 1024) return number + 'bytes';
    number = number / 1024;
    if (number < 1024) return number.toFixed(1) + 'KB';
    number = number / 1024;
    return number.toFixed(1) + 'MB';
 }

</script>

Components S10 Framework