BAC Calculator

From AODWiki

Jump to: navigation, search

Contents

Purpose and History

A quick Google search will lead one to a long list of dozens if not hundreds of examples of BAC calculators on the web. So why would anyone want to make another? The answer is immediately apparent if you visit some of the more popular (i.e., higher ranking) sites. Many of these calculators fail to ask for important information, such as gender. Further, few of the calculators state which formula is being used to create the estimate. Therefore, using any of these calculators requires a leap of faith.

So in the spirit of AODWiki, this calculator project was begun. Not only will the formula be explicit, the JavaScript will be posted and available for modification and use within other�s sties. To see the formula behind the calculations, see the e-BAC formula.

Usage

Feel free to cut and paste the JavaScript and HTML posted on this site for use within other sites. Because it is possible that modifications to the code would cause errors, this page is protected. If you would like to suggest a change to the script, offer it within the associated discussion page. After testing, the administrator will make valued changes. You can see a Live Example of this code as it stands today.

In keeping with the AODWiki tradition, this code may be used as long as the AODWiki source is cited. Commercial use is restricted to sites that offer this calculator free of charge. The script must remain in the public domain. See AODWiki:Copyrights for more information about AODWiki copyright policies.

JavaScript

//===================AODWiki e-BAC Calculator====================
//========================version 1.0============================
//============Available for noncommercial distribution===========
//==== See http://aodwiki.org/index.php/AODWiki:Copyrights ======
//================ for more information =========================
//=========== Offered without Warranty ==========================

//================================Declare Valiables
var beers;
var wine;
var spirits;
var hours;
var pounds;
var genderconstant;
//===============================Calculation function
function eBAC(form){
//=====================Error checking and set value to null
form.estimate.value="";
if (form.num_beers.value =="") {
form.num_beers.value = "0";
}
if (form.num_wine.value =="") {
form.num_wine.value = "0";
}
if (form.num_spirits.value =="") {
form.num_spirits.value ="0";
}
if (form.num_hours.value =="") {
alert ("Please complete the HOURS field");
return;
}
if (form.num_pounds.value =="") {
alert ("Please complete the WEIGHT field");
return;
}
//=======================================Read in entered values
beers=eval(form.num_beers.value);
wine=eval(form.num_wine.value);
spirits=eval(form.num_spirits.value);
hours=eval(form.num_hours.value);
pounds=eval(form.num_pounds.value);

if (form.Gender[0].checked) {
var genderconstant=7.5;
}
else if (form.Gender[1].checked) {
var genderconstant=9;
}
//======================================Calculate estimate
var standarddrinks=beers+wine+spirits;
var bacestimate=((standarddrinks/2)*(genderconstant/pounds))-(0.017*hours);
if (bacestimate< 0) {
bacestimate=0;
}
if (bacestimate>.50) {
alert ("Your estimate exceeds .50, please check your entries");
return;
}
//========================================Return result
form.estimate.value=bacestimate;
}

Form HTML

<form >
<p>Please complete the following items, then press calculate to obtain the BAC estimate</p>
<div id="entry_items">
<label>Male<input type="radio" name="Gender" value="Male" /></label>
or <label>Female<input name="Gender" type="radio" value="Female" checked="checked" /></label>
<div id="drinklist">
<p>Number of ...</p>
<label><strong>12 oz</strong> beers <input name="num_beers" type="text" id="num_beers" size="3" maxlength="2" /></label>
<label><strong>5 oz</strong> glasses of wine<input name="num_wine" type="text" id="num_wine" size="3" maxlength="2" /></label>
<label><strong>1.5 oz</strong> measures of spririts <input name="num_spirits" type="text" id="num_spirits" size="3" maxlength="2" /></label>
</div>
<label>Over how many hours<input name="num_hours" type="text" id="num_hours" size="3" maxlength="2" /></label>
<label>Your weight in pounds<input name="num_pounds" type="text" id="num_pounds" size="3" maxlength="3" /></label>
</div>
<div id="results">
<label><input type="button" name="Button" value="Calculate Estimate" onclick="javascript:eBAC(this.form)"/> </label>
<label><input name="Reset" type="reset" value="Reset" /></label>
<div id="result">
<label>Estimated BAC<input name="estimate" type="text" id="estimate" size="5" maxlength="5" /></label>
</div>
</div>
</form>


Disclaimers

Estimates are provided for educational purposes only. Do not drink and drive! Do not use these estimates as a basis for making a decision about drinking or driving.

For information about the formulas used in this estimate click here. For information about using this calculator on your own site see the AODWiki eBAC Calculator discussion.

Live Example

To see a beta test of the calculator in its current form, see eBAC Calculator Beta.