Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Scripts

Reply
 
LinkBack Thread Tools Display Modes
Old 10-18-2011, 02:42 AM   #1
New Member
 
Join Date: May 2011
Posts: 4
Default Help with if else if script

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");
   }
Waubain is offline   Reply With Quote


Old 10-19-2011, 02:07 AM   #2
Silver Member
 
Join Date: Jul 2011
Posts: 146
Default

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) {
case "100020":
window.location="http://www.mywebsite.com/echart/100020/general.htm"; break;
case "123440":
window.location="http://www.mywebsite.com/echart/123440/general.htm"; break;
case "456987":
window.location="http://www.mywebsite.com/echart/456987/general.htm"; break;
default:
alert("Patient ID not found");
}
DesignerBill is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:18 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.