LeadMaster Knowledgebase - 800-699-4164
Search:     Advanced search
Browse by category:
Knowledgebase | News | Downloads | Ask a Question | LeadMaster |

Sample Javascript for a Smart Form

Article ID: 458
Last updated: 21 Apr, 2020
Add comment
Views: 0
Comments: 0

 In LeadMaster you can add Javascript to a smart form for things like validation and calculations.  Here's an example:

<script type="text/javascript">
function EstRevPerSqFt()
{
var a = new Array(2);
a[0] = $( "#Q204 option:selected" ).text();
a[0] = a[0].replace(',','');
a[1] = $("#Q190").val();
var EstRevPerSqFt =  1;
for(var i=0; i < 2; i++)
{                  
a[i] =  a[i].replace('$','');
}
if (a[0] > 0 && a[1] > 0) {
EstRevPerSqFt = ((a[0]/a[1])/12);
EstRevPerSqFt = EstRevPerSqFt.toFixed(2);
EstRevPerSqFt = "$" + EstRevPerSqFt;
}
$('#Q189').attr('value', EstRevPerSqFt);
$('#Q189').change();
}
function FracSales()
{
var b = new Array(2);
b[0] = $( "#Q204 option:selected" ).text();
b[0] = b[0].replace(',','');
b[1] = $("#Q172").val();
var FracSales =  0;
for(var i=0; i < 2; i++)
{                  
b[i] =  b[i].replace('$','');
}
if ( b[1] == "397:") {
b[1] = .95;
} else if (b[1] == "398:") {
b[1] = .75;
} else if (b[1] == "399:") {
b[1] = .55;
} else if (b[1] == "400:") {
b[1] = .35;
} else if (b[1] == "401:") {
b[1] = .15;
}
else {
b[1]=0;
}
if (b[0] > 0 && b[1] > 0) {
FracSales = (b[0] * b[1]);
FracSales = FracSales.toFixed(2);
FracSales = "$" + FracSales;
}
$('#Q193').attr('value', FracSales);
$('#Q193').change();
}
function AnnPipePot()
{
var c = new Array(2);
c[0] = $("#Q178").val();
c[1] = $( "#Q204 option:selected" ).text();
c[1] = c[1].replace(',','');
var AnnPipePot =  0;
for(var i=0; i < 2; i++)
{                  
c[i] =  c[i].replace('$','');
}
if ( c[0] == "418:") {
c[0] = 1;
} else if (c[0] == "419:") {
c[0] = 2;
} else if (c[0] == "420:") {
c[0] = 3;
} else if (c[0] == "421:") {
c[0] = 4;
} else if (c[0] == "422:") {
c[0] = 5;
} else if (c[0] == "423:") {
c[0] = 6;
} else if (c[0] == "424:") {
c[0] = 7;
} else if (c[0] == "425:") {
c[0] = 8;
} else if (c[0] == "426:") {
c[0] = 9;
} else if (c[0] == "427:") {
c[0] = 10;
} else if (c[0] == "428:") {
c[0] = 11;
} else if (c[0] == "429:") {
c[0] = 12;
}
else {
c[0]=0;
}
if (c[0] > 0 && c[1] > 0) {
AnnPipePot = ((c[1]/12)*c[0]);
AnnPipePot = AnnPipePot.toFixed();
AnnPipePot = "$" + AnnPipePot;
}
$('#Q194').attr('value', AnnPipePot);
$('#Q194').change();
}
function EstAnnSalesGoal()
{
var d = new Array(2);
d[0] = $( "#Q194").val();
d[0] = d[0].replace(',','');
d[1] = $("#Q195").val();
var EstAnnSalesGoal =  0;
for(var i=0; i < 2; i++)
{                  
d[i] =  d[i].replace('$','');
}
if (d[0] > 0 && d[1] > 0) {
EstAnnSalesGoal = ((d[0]/d[1])*100);
EstAnnSalesGoal = EstAnnSalesGoal.toFixed(2);
EstAnnSalesGoal = EstAnnSalesGoal + "%";
}
$('#Q196').attr('value', EstAnnSalesGoal);
$('#Q196').change();
}
$(document).ready(function() {
$("#Q196").val($("#Q196").val() + '%');
$("#Q189").val('$' + $("#Q189").val());
$("#Q193").val('$' + $("#Q193").val());
$("#Q194").val('$' + $("#Q194").val());
$('#Q172').change(function(){
EstRevPerSqFt();
FracSales();
AnnPipePot();
EstAnnSalesGoal();
});
$('#Q178').change(function(){
EstRevPerSqFt();
FracSales();
AnnPipePot();
EstAnnSalesGoal();
});
$('#Q204').change(function(){
EstRevPerSqFt();
FracSales();
AnnPipePot();
EstAnnSalesGoal();
});
$('#Q190').change(function(){
EstRevPerSqFt();
FracSales();
AnnPipePot();
EstAnnSalesGoal();
});
$('#Q195').change(function(){
EstRevPerSqFt();
FracSales();
AnnPipePot();
EstAnnSalesGoal();
});
$("img[src='images/Update_Go_New.png']").click(function(){
tempValue = $("#Q196").val();
tempValue = tempValue.replace('%','');
$("#Q196").val(tempValue);
tempValue = $("#Q189").val();
tempValue = tempValue.replace('$','')
$("#Q189").val(tempValue);
tempValue = $("#Q193").val();
tempValue = tempValue.replace('$','')
$("#Q193").val(tempValue);
tempValue = $("#Q194").val();
tempValue = tempValue.replace('$','')
$("#Q194").val(tempValue);
});
});
</script>
Add comment
Prev   Next
This is how you make database fields read-only on a Smart Form     Adding/Editing Custom Forms

Others in this category
document How to make mapped custom form fields hidden on the HTML Form
document Adding a Section
document How to create a 'Typed Signature' field on a Smart Form
document Individual Custom Fields for the Record, Contact & Opportunity Pages
document Preview Custom Form
» More articles