Practicing some JS by creating a basic app integrated with TaffyDB. It stores medical codes. I've tried searching for a solution to this but can't seem to get it working.
Goal: On click of button, JS function is called passing the innerHTML value into the TaffyDB query which searches by "code". It then alerts() the user with the description of that code.
Problem: I keep getting "undefined" when calling the function.
TaffyDB snippet:
diagnosisCodes = TAFFY([
{code_id:'C001', code:'460', description:'Acute Nasopharyngitis(Common Cold)'},
{code_id:'C002', code:'708.2', description:'Urticaria Due to Cold and Heat'},
{code_id:'C003', code:'778.2', description:'Cold Injury Syndrome of Newborn'},
{code_id:'C004', code:'975.6', description:'Poisoning by Anti-Common Cold Drugs'},
]);
HTML snippet:
<h2 class='code_categories' id='diagnosis_title'>Diagnosis Codes</h2>
<div id='diagnoses_COLD'>
<h4 id='column_titles'>Cold-Related</h4>
<button id='button' onclick="testing()">460</button>
JS Function:
function testing() {
//grab element value:
var obj = document.getElementById('button').innerHTML.value;
//pass element value into TaffyDB query:
var dxDesc = diagnosisCodes({code:obj}).first().description;
//'alert' description of the code
alert(dxDesc);
}
This function returns 'undefined'. However, var obj is correctly assigned a string value. Also, the query works fine when passing a function parameter. For example, this alerts with the correct description:
function getDxDesc(name) {
var obj2 = diagnosisCodes({code:name}).first().description;
alert(obj2);
}
My problem is getting the entire thing to work in unison.
.value
is used to get the value of a user input. Just use.innerHTML
by itself:DEMO