FPU Packet Pickup Javascript¶
Return to Financial Peace University Packet Pickup Project.
Below is the javascript used for the FPUPacketPickup sample project with some high level explanation following.
Note
This file should be located under Admin > Special Content > Text tab, and be named FPUPacket.js.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | $(function () { $("#wandtarget").keypress(function(ev) { if (ev.which !== 13) return true; $.action(); return false; }); $("#action").click(function(ev) { ev.preventDefault(); $.action(); return false; }); $.action = function() { var v = $("#wandtarget").val(); if ((v.split("-").length - 1) > 1) { $("#wandtarget").val(''); $("#output").html(''); return; } var q = $("#wandform").serialize(); $.post("/PyScriptForm/", q, function (ret) { $("#output").html(ret); $("#wandtarget").focus(); }); }; $("#clear").click(function(ev) { ev.preventDefault(); if($("#paidnochange").is(':checked') && $("#pickedup").is(':checked')) $("#wandtarget").val('').focus(); else { $('#paidnochange').prop('checked', true); $('#pickedup').prop('checked', true); } $("#output").html(""); }); $("#wandtarget").focus(); }); |
- Lines 6 and 8
Pressing “Enter” or clicking the “Action” button will start the
action()
, processing the barcode.- Lines 15-19
If there is a barcode already there, erase it first so that the form is ready to scan the next barcode.
- Lines 20-24
Send the form inputs via POST method to the script on the server.
- Lines 26-35
Reset the form to the default values when the “Clear” button is clicked.