I am using a two-dimensional array that contains info about patients, and another one about diagnoses. What I’m trying to do is link a certain patient with a diagnosis. The problem appears when the patient is not listed in my PatientsDB array database: I wan’t the new patients to be displayed alphabetically in the select form ‘patients’ and if possible, the latest entered element to be selected. I tried to sort the PatientDB array first, but without any success.
1.
Is there a way to sort and display the options in the select form by patient name, id, address, etc.?
Is there an alternative way to add new patient info?
Can the newly generated PatientsDB array be saved for further reference when I close the hml document?
Thank you for your attention.
<html>
<head>
<title>dynamically sort the options in a select form</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-5″>
<SCRIPT LANGUAGE=”JavaScript1.1″>
<!– start script
// stuff “rows” of data for our pseudo-two-dimensional array
function patient(name,PatientID, town, address, day){
this.name = name
this.PatientID = PatientID
this.town = town
this.address = address
this.day = day
}
// create our pseudo-two-dimensional array
PatientsDB = new Array()
PatientsDB[0] = new patient(“Adam”,”00272″,”h”,”i”,”20.07″);
PatientsDB[1] = new patient(“Brian”,”00351″,”g”,”j”,”20.06″);
PatientsDB[2] = new patient(“Carl”,”15764″,”f”,”k”,”20.05″);
PatientsDB[3] = new patient(“Donald”,”05786″,”e”,”l”,”20.04″);
// stuff “rows” of data for our pseudo-two-dimensional array
function diagnose(diagnose, diagnosecode){
this.diagnose = diagnose
this.diagnosecode = diagnosecode
}
// create our pseudo-two-dimensional array
DiagnosesDB = new Array()
DiagnosesDB[0] = new diagnose(“Acute Enterocolitis”,”009″)
DiagnosesDB[1] = new diagnose(“Acute Tracheobronchitis”,”466.0″);
// Populating the PatientsDB array with new data
function NewPatient(){
var NewName = prompt(“Patient Name: “,””);
var NewPatientID = prompt(“Patient ID: “,””);
var NewTown = prompt(“Town: “,””);
var NewAddress = prompt(“Address: “,””);
var NewDay = prompt(“Date (dd.mm): “,””);
PatientsDB[PatientsDB.length] = new patient(NewName,NewPatientID,NewTown,NewAddress,NewDay);
PatientsDB.sort()
var page = “” // start assembling next part of page and form
page += “<SELECT NAME=’patients’> “
// build popup list from array patient names
for (var i = 0; i < PatientsDB.length; i++) {
page += “<OPTION” // OPTION tags
if (i == 0) { // pre-select first item in list
page += ” SELECTED”
}
page += “>” + PatientsDB[i].name
}
page += “</SELECT><P>” // close selection item tag
document.getElementById(‘PatientsList’).innerHTML = page;
}
// end script –>
</SCRIPT>
<BODY>
<H1><a href=”#” onClick=
“NewPatient();
return false;”>Enter new patient data</a> </H1>
<HR>
<H1><a href=”#” onClick=
“alert(‘Patient Name: ‘ + PatientsDB[window.document.select.patients.selectedIndex].name);
alert(‘Patient ID: ‘ + PatientsDB[window.document.select.patients.selectedIndex].PatientID);
alert(‘Diagnose: ‘ + DiagnosesDB[window.document.select.diagnose.selectedIndex].diagnose);
alert(‘Code of the Diagnose: ‘ + DiagnosesDB[window.document.select.diagnose.selectedIndex].diagnosecode);
return false;”>View the selected patient data</a></H1>
<HR>
<FORM name=”select”>
<SCRIPT LANGUAGE = “JavaScript”>
<!– start script again
var page = “” // start assembling next part of page and form
page += “Select a patient: “
page += “<div id=’PatientsList’><SELECT NAME=’patients’> “
// build popup list from array patient names
for (var i = 0; i < PatientsDB.length; i++) {
page += “<OPTION” // OPTION tags
if (i == 0) { // pre-select first item in list
page += ” SELECTED”
}
page += “>” + PatientsDB[i].name
}
page += “</SELECT></div><P>” // close selection item tag
document.write(page) // lay out this part of the page
var pagedg = “” // start assembling next part of page and form
pagedg += “Select a patient’s diagnose: “
pagedg += “<SELECT NAME=’diagnose’> “
// build popup list from array patient names
for (var i = 0; i < DiagnosesDB.length; i++) {
pagedg += “<OPTION” // OPTION tags
if (i == 0) { // pre-select first item in list
pagedg += ” SELECTED”
}
pagedg += “>” + DiagnosesDB[i].diagnose
}
pagedg += “</SELECT><P>” // close selection item tag
document.write(pagedg) // lay out this part of the page
// really end script –>
</SCRIPT>
</FORM>
</BODY>
</HTML>