Javascript code works only when the page loads

Posted by victor on Stack Overflow See other posts from Stack Overflow or by victor
Published on 2010-03-30T05:47:10Z Indexed on 2010/03/30 5:53 UTC
Read the original article Hit count: 249

Filed under:

I have a page with a dropdown and two textboxes. The javascript code checks to make sure that if the dropdown says Appointment Made or Patient Scheduled, the appropriate text boxes will have dates in them. When the page loads and the drop down shows either of the two above, all works fine but when I change the drop down the script does not work. I have put an alert statament after the third line and do see that when I make a change to patient_status, the variable a gets updated but for some reason the script fails and does not prompt.

For example if the page loads and Appointment Made is selected, the script will prompt, but if I change the drop down to Patient Scheduled, it will not prompt.

Thank You.

function calculate() { a= document.getElementById("EditRecordpatient_status").value; b= document.getElementById("EditRecordSurgery_Date").value; c= document.getElementById("EditRecordConsult_Date").value;

alert(a); alert(b); alert(c);

if (a=="Appointment Made" && c=="") { alert('You have scheduled a patient for consultation but the consult date is missing!'); return false; } else if (a=="Patient Scheduled" && b=="") { alert('You have scheduled a patient for surgery but the surgery date is missing!'); return false; } else { return true; } }

document.getElementById("Mod0EditRecord").onclick=calculate;

© Stack Overflow or respective owner

Related posts about javascript-events