Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery script to show data-message
    primarykey
    data
    text
    <p>I'm using jQuery validator() to display HTML form 'data-message' if the field is invalid. Is there a way call the data-message on command?</p> <p>For example, instead of my JS throwing an alert with </p> <pre><code>alert("Wrong file!"); </code></pre> <p>I would like to instead show the <code>data-message</code> from the HTML form.</p> <p>Here's my form input file field:</p> <pre><code>&lt;input type="file" name="orders_csv" id="orders_csv" required="required" data-message="Please attach the morders.csv file."&gt; </code></pre> <p>And here's my current JS:</p> <pre><code>$(document).ready(function () { $("#upload-form").validator({ position: 'top center', offset: [-12, 40], relative: true, accept: "csv", message: '&lt;div&gt;&lt;em&gt;&lt;/em&gt;&lt;/div&gt;' }) // make sure that mcust.csv is the attached file. If not, throw alert message $("input#dealers_csv").on("change", function() { $('#loader').hide(); var dealers = $("input#dealers_csv"); var arrfilepath = dealers.val().split("\\"); var filename = arrfilepath[arrfilepath.length - 1]; if (filename != "mcust.csv") { alert($("#dealers_csv").data("message")); dealers.val(''); } }); // make sure that morders.csv is the attached file. If not, throw alert message $("input#orders_csv").on("change", function() { $('#loader').hide(); var orders = $("input#orders_csv"); var arrfilepath2 = orders.val().split("\\"); var filename2 = arrfilepath2[arrfilepath2.length - 1]; if (filename2 != "morders.csv") { alert($("#orders_csv").data("message")); orders.val(''); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload