Here's some of our recent work in JavaScript: a unique calculator in a web page, with some PHP thrown in via AJAX for good measure.
We can't share all of it - it's proprietary and in production - and a key part of the client's site.
Of course we use JS for form validation - not the most interesting part of the work -
function validateForm() {
window.alert(5 + 16);
var x = document.forms["theform"]["t12"].value;
if (x == null || x == "") {
alert("DAYS PER WEEK IN SERVICE must be filled out.");
return false;
}
var y = document.forms["theform"]["zip"].value;
if (y == null || y == "") {
alert("ZIP CODE must be filled out.");
return false;
}
var a = document.forms["theform"]["t14"].value;
if (a == null || a == "") {
alert("HOURS SPENT PER DAY must be filled out. ");
return false;
}
}
But then we get into the AJAX calls to the PHP code, which looks up data in a MYSQL table - here's just a small part of it as an example :
///////////////////////////////
function frate()
{
var zip = $("#zip").val();
console.log(zip);
$.ajax({
type: "POST",
url: "rateseek2d2.php",
data: "zip="+zip,
cache: false,
success: function(response)
{
// alert(response);
// document.getElementById("dd2").innerHTML = response;
$('#rate').val(response);
//response =response*100;
r=response*100;
r= parseFloat(Math.round(r * 100) / 100).toFixed(0);
$('#prate').val(r);
// $("#dd2").html(response);
}
});
}
and then the calculator code itself - or at least some small parts of it:
function calc() {
var dd = $("#totalDD").val();
var t12 = $("#t12").val();
var vr = $("#rate").val();
var t14 = $("#t14").val();
var t16 = $("#t16").val();
//var t18 = $("#t18").val();
t18 = t12 * t14 * t16 * 52
document.getElementsByName('t18')[0].value = t18;
var t20 = $("#t20").val();
var t22 =t18*t20
document.getElementsByName('t22')[0].value = t22;
var t24 = $("#t24").val();
var t26 = $("#t26").val();
var t28 = $("#t28").val();
The whole thing came together into an easily used form based web calculator - an educational process used to drive sales.
|