Help with if else if script

Waubain

New Member
I have 3 folders named 100020, 123440, and 456987 all contain a general.htm that starts a separate lesson for my pharmacy students. I have a single text box form with a submit button

Code:
<form onsubmit="return handleThis(this)" name="patientfindform">

The commented out function below works. I would now like be able to alert the student that they entered the wrong number. I tried variations of the code below but does not work. When I submit, the textbox clears and nothing happens.

Any help would be appreciated.

Code:
function handleThis(formElm)
/*{
window.location="http://www.mywebsite.com/echart/"+formElm.patient_num.value+"/general.htm";
return false;
}
*/

if (formElm.patient_num.value = 100020)
   {
   window.location="http://www.mywebsite.com/echart/"+formElm.patient_num.value+"/general.htm";
   }
else if (formElm.patient_num.value = 123440)
   {
   window.location="http://www.mywebsite.com/echart/"+formElm.patient_num.value+"/general.htm";
   }
else if (formElm.patient_num.value = 456987)
   {
   window.location="http://www.mywebsite.com/echart/"+formElm.patient_num.value+"/general.htm";
   }
else
   {
   alert("Patient ID not found");
   }
 
You have made a very common Javascript beginner mistake. Here's a hint - check your if statement syntax. Actually, what you are doing would be better with a switch statement:
Code:
switch (formElm.patient_num.value) {
[INDENT]case "100020":
[INDENT]window.location="http://www.mywebsite.com/echart/100020/general.htm";
break;[/INDENT]
case "123440":
[INDENT]window.location="http://www.mywebsite.com/echart/123440/general.htm";
break;[/INDENT]
case "456987":
[INDENT]window.location="http://www.mywebsite.com/echart/456987/general.htm";
break;[/INDENT]
default:
[INDENT]alert("Patient ID not found"); [/INDENT]
}[/INDENT]
 
Top