function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for (var i = 0; i < colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[1].cells[i].innerHTML; /* set new id for the symptom select tag which is found in the first cell of every row * this makes the symptom select tag id dynamic and different for each table row * the id should be the rowCount +1000 to avoid a similar id with prompt div tag id set below */ if (i == 1) { newcell.childNodes[1].id = (rowCount + 1000); //alert(newcell.childNodes[1].nodeName); } /* * set new value for the prompt div tag */ if (i == 3) { table.rows[rowCount].cells[3].innerHTML = ''; table.rows[rowCount].cells[3].innerHTML = '
'; } if (i == 4) { var promptId = rowCount + 100; table.rows[rowCount].cells[4].innerHTML = ''; table.rows[rowCount].cells[4].innerHTML = ''; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for (var i = 0; i < rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if (null != chkbox && true == chkbox.checked) { if (rowCount <= 2) { alert("Cannot delete all the rows."); break; } table.deleteRow(i); rowCount--; i--; } } } catch (e) { alert(e); } } /* *code for selecting symptoms */ function showPrompt(symptom_id, prompt_div_id) { if (symptom_id == ""){ return; } $.ajax({ method: 'POST', url: '/triage/get_prompt', data: {'symptom_id' : symptom_id}, success: function(response){ var returnText = response.split('&&&&'); var prompt = returnText[0]; var reference = returnText[1]; document.getElementById((prompt_div_id - 1000)).innerHTML = '' + prompt + '
'; document.getElementById(prompt_div_id - 900).innerHTML = reference; }, error: function(jqXHR, textStatus, errorThrown) { alert(JSON.stringify(jqXHR)); console.log(JSON.stringify(jqXHR)); } }); }