I have this form in a page block:
$aForm = array(
'form_attrs' => array(
'name' => 'form_general_health',
'method' => 'post',
),
'params' => array (
'db' => array(
'table' => 'general_health', // table name
'key' => 'general_health_id', // key field name
'uri' => '', // uri field name
'uri_title' => '', // title field to generate uri from
'submit_name' => 'submit_general_health_form', // some filed name with non empty value to determine if the for was submitted,
// in most cases it is submit button name
),
'csrf' => array(
'disable' => true, //if it wasn't set or has some other value then CSRF checking is enabled for current form, take a look at sys_security_form_token_enable to disable CSRF checking completely.
)
),
'inputs' => array(
'header1' => array(
'type' => 'block_header',
'caption' => _t("_General_health_txt"),
),
'Ht_Ft' => array(
'type' => 'text',
'name' => 'Height_Feet',
'attrs' => array(
'id' => 'Height_Feet',
'onblur' => '',
),
'caption' => _t("_Height_Feet"),
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Ht_In' => array(
'type' => 'text',
'name' => 'Height_Inches',
'attrs' => array(
'id' => 'Height_Inches',
),
'caption' => _t("_Height_Inches"),
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Weight' => array(
'type' => 'text',
'name' => 'Weight',
'attrs' => array(
'id' => 'Weight',
),
'caption' => _t("_Weight"),
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'BMI' => array(
'type' => 'text',
'name' => 'BMI',
'attrs' => array(
'id' => 'BMI',
'readonly' => true,
),
'caption' => _t("_BMI"),
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Weight_Is' => array(
'type' => 'text',
'name' => 'WeightOpinion',
'caption' => _t("_Weight Opinion"),
'value' => '',
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Appetite_Is' => array(
'type' => 'text',
'name' => 'Appetite',
'caption' => _t("_Appetite"),
'value' => '',
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Nutrition_Is' => array(
'type' => 'text',
'name' => 'Nutrition',
'caption' => _t("_Nutrition"),
'value' => '',
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Sleep_Hours' => array(
'type' => 'text',
'name' => 'SleepHours',
'caption' => _t("_Sleep_Hours"),
'value' => '',
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Sleep_Is' => array(
'type' => 'text',
'name' => 'SleepHoursOpinion',
'caption' => _t("_Sleep_Is"),
'value' => '',
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Sleep_Interference' => array(
'type' => 'text',
'name' => 'SleepInterferance',
'caption' => _t("_Sleep_Interference"),
'value' => '',
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Known_Med' => array(
'type' => 'textarea',
'name' => 'KnownMed',
'caption' => _t("_Known_Med"),
'value' => $KnownMed,
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'General_Health' => array(
'type' => 'textarea',
'name' => 'GeneralHealth',
'caption' => _t("_General Health"),
'value' => $GeneralHealth,
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'Client' => array(
'type' => 'hidden',
'name' => 'client_id',
'value' => $client,
'db' => array (
'pass' => 'Xss', // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
),
),
'header1_end' => array(
'type' => 'block_end'
),
'submit_send' => array(
'type' => 'submit',
'colspan' => true,
'name' => 'submit_general_health_form',
'value' => _t("_Submit_general_health"),
),
),
);
$oForm = new BxTemplFormView ($aForm);
$oForm->initChecker();
if ($oForm->isSubmittedAndValid ()) {
$sClient = $_POST['client_id'];
// add additional vars to database, in this case creation date field is added
$aValsAdd = array (
'input_by' => $_COOKIE['memberID'],
);
if ($oForm->insert ($aValsAdd)) {
header ("Location: theraprep-medications?client=$sClient");
}
}
return array($sStatusText . $oForm->getCode(), array(), array(), false);
Need to know where to put this function:
<script type="text/javascript" language="javascript">
function f_calBMI() {
var v_heightF = document.getElementById("Height_Feet").value;
var v_heightI = document.getElementById("Height_Inches").value;
var v_weight = document.getElementById("Weight").value;
var v_height = 0 ;
var v_bmi = "" ;
if ((v_heightF != "") && (v_weight!= "") && !isNaN(v_heightF) && !isNaN(v_weight)) {
//calculate height
if (v_heightI != "" && !isNaN(v_heightI)) {
v_height = parseFloat(v_heightF)*12 + parseFloat(v_heightI) ;
}
else { v_height = parseFloat(v_heightF)*12 ;}
v_bmi = parseFloat(v_weight)*703/(v_height*v_height) ;
v_bmi = Math.round(parseFloat(v_bmi)*10) ;
v_bmi = v_bmi/10 ;
document.getElementById("BMI").value = v_bmi ;
} else {
document.getElementById("BMI").value = "";
}
}
window.onload = function() {
f_calBMI() ;
document.getElementById("Height_Feet").onblur = f_calBMI ;
document.getElementById("Height_Inches").onblur = f_calBMI ;
document.getElementById("Weight").onblur = f_calBMI ;
document.getElementById('form_general_health').onclick = f_calBMI ;
}
</script>
This function calculates the input of the Height and Weight of a person to come up with their Body Mass Index. So, what it does is, after the height and weight fields have been filled in, it automatically calculates and displays the BMI in the BMI field. But without a button click, using onblur instead.
I have gotten all the fields duplicated from my old style input fields to dolphin style input fields, but the function is not working, nor can i see it when using firebug.
Any help is appreciated and Thanks in advance.