Results 1 to 2 of 2

Thread: JavaScript help

  1. #1
    Jeremy720 is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default JavaScript help

    Hey there! Don't know if asking a javascript question here is cool, but I'll give it a shot. More of a general logic question anyway.
    I have a project called "Robot Nurse" that assigns a doctor based on the users ailment. I need to get it to accept several acceptable and unacceptable keywords and have it assign the appropriate doc based on the 1st acceptable ailment they type in. If none are found, it assigns the appropriate message (the crematorium!) I can't get it to do this consistently. Any help would be greatly appreciated.

    Here's what I have so far. It works, but isn't perfect (it's a bit lengthy too)...

    ...
    <script type="text/javascript">
    function findDoctor()
    {
    var injury //string from textbox
    var wordBank; //array of words
    var kimball = false;
    var frankenstein = false;
    var kovak = false;
    var clemente = false;
    var bob = false;
    var carter = false;
    var none = false;
    var ailment = "";
    var pic1;
    var pic2;
    var pic3;
    var pic4;
    var pic5;
    var pic6;
    var pic7;
    var pic8;
    var path = "doctor_images\\";
    var ww;

    ailment = document.getElementById ( "ailmentField" ).value;
    wordBank = ailment.split(" ");
    path = "doctor_images\\";
    //process the array to look for key words that are acceptable

    for (ww = 0; ww < wordBank.length; ww++)
    {
    switch (wordBank[ww])
    {
    case "puncture":
    ailment = wordBank[ww];
    kimball = true;
    ww++;
    break;
    case "wound":
    ailment = wordBank[ww];
    kimball = true;
    ww++;
    break;
    case "pierce":
    ailment = wordBank[ww];
    kimball = true;
    ww++;
    break;
    case "stab":
    ailment = wordBank[ww];
    kimball = true;
    ww++;
    break;
    case "stabbed":
    ailment = wordBank[ww];
    kimball = true;
    ww++;
    break;


    case "broken":
    ailment = wordBank[ww];
    frankenstein = true;
    ww++;
    break;
    case "leg":
    ailment = wordBank[ww];
    frankenstein = true;
    ww++;
    break;
    case "finger":
    ailment = wordBank[ww];
    frankenstein = true;
    ww++;
    break;
    case "arm":
    ailment = wordBank[ww];
    frankenstein = true;
    ww++;
    break;
    case "neck":
    ailment = wordBank[ww];
    frankenstein = true;
    ww++;
    break;
    case "joint":
    ailment = wordBank[ww];
    frankenstein = true;
    ww++;
    break;
    case "hands":
    ailment = wordBank[ww];
    frankenstein = true;
    ww++;
    break;
    case "bone":
    ailment = wordBank[ww];
    frankenstein = true;
    ww++;
    break;


    case "digestion":
    ailment = wordBank[ww];
    kovak = true;
    ww++;
    break;
    case "stomach":
    ailment = wordBank[ww];
    kovak = true;
    ww++;
    break;
    case "indigestion":
    ailment = wordBank[ww];
    kovak = true;
    ww++;
    break;
    case "bowels":
    ailment = wordBank[ww];
    kovak = true;
    ww++;
    break;
    case "internal":
    ailment = wordBank[ww];
    kovak = true;
    ww++;
    break;
    case "ache":
    ailment = wordBank[ww];
    kovak = true;
    ww++;
    break;


    case "mental":
    ailment = wordBank[ww];
    clemente = true;
    ww++;
    break;
    case "psycho":
    ailment = wordBank[ww];
    clemente = true;
    ww++;
    break;
    case "schitzophrenic":
    ailment = wordBank[ww];
    clemente = true;
    ww++;
    break;
    case "dilusional":
    ailment = wordBank[ww];
    clemente = true;
    ww++;
    break;
    case "bi-polar":
    ailment = wordBank[ww];
    clemente = true;
    ww++;
    break;
    case "head":
    ailment = wordBank[ww];
    clemente = true;
    ww++;
    break;


    case "cold":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "sore":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "flu":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "cough":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "respiritory":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "sniffle":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "mucus":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "wheezing":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "fatigued":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;
    case "sneezing":
    ailment = wordBank[ww];
    bob = true;
    ww++;
    break;



    default:
    ailment = wordBank[ww];
    kimball = false;
    frankenstein = false;
    kovac = false;
    clemente = false;
    bob = false;
    carter = false;
    break;

    }
    }

    path = "doctor_images\\";
    pic1 = path + 1 + ".jpg";
    pic2 = path + 2 + ".jpg";
    pic3 = path + 3 + ".jpg";
    pic4 = path + 4 + ".jpg";
    pic5 = path + 5 + ".jpg";
    pic6 = path + 6 + ".jpg";
    pic7 = path + 7 + ".jpg";
    pic8 = path + 8 + ".jpg";
    pic9 = path + 9 + ".jpg";


    if (kimball.toString() == "true")
    {
    document.getElementById("doctorfield").value =
    ("Please visit room 200 to visit with Dr. Kimball");
    document.firstImg.src = pic1;
    }
    else if (frankenstein.toString() == "true")
    {
    document.getElementById("doctorfield").value =
    ("Please visit room 300 to visit with Dr. Frankenstein");
    document.firstImg.src = pic2;
    }
    else if (kovak.toString() == "true")
    {
    document.getElementById("doctorfield").value =
    ("Please visit room 400 to visit with Dr. Kovak");
    document.firstImg.src = pic3;
    }
    else if (clemente.toString() == "true")
    {
    document.getElementById("doctorfield").value =
    ("Please visit room 500 to visit with Dr. Clemente");
    document.firstImg.src = pic4;
    }
    else if (bob.toString() == "true")
    {
    document.getElementById("doctorfield").value =
    ("Please visit room 600 to visit with Dr. Bob");
    document.firstImg.src = pic5;
    }
    else
    {
    document.getElementById("doctorfield").value =
    ("We're sorry, but you're going to die. Please visit the crematorium!");
    document.firstImg.src = pic9;
    }
    }
    function load()
    {
    var pic8;
    var path = "doctor_images\\";
    pic8 = path + 8 + ".jpg";
    document.firstImg.src = pic8;
    }

    </script>
    </head>
    <body bgcolor="lightblue" onload = "load()">
    <table align = "center" bgcolor = "green">
    <tr><td><h1 align = "center">I am your Robo-Nurse! <br/>
    What seems to be the problem?</h1></td></tr>
    <tr><td align = "center"><input id = "ailmentfield" type = "text" size = "50"/></td></tr>
    <tr><td align = "center"><input type = "button" value = "Assign me a doctor!"
    onclick = "findDoctor()" /></td></tr>
    <tr><td align = "center"><input id = "doctorfield" type = "text" size = "67"/></td></tr>
    <tr><td align = "center"><img name = "firstImg" src = ""/></td></tr>
    </body>
    </html>

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Java and JavaScript are two very different beasts. You will likely get better help on this at a JavaScript forum. Best of luck!

    edit: but you've posted here before, so you should know this?!

Similar Threads

  1. Enabling Javascript
    By drewsonoffergus in forum Networking
    Replies: 1
    Last Post: 08-06-2011, 09:42 PM
  2. javascript
    By fiero in forum New To Java
    Replies: 1
    Last Post: 09-22-2008, 02:45 PM
  3. Javascript into Excel
    By gdj100 in forum Advanced Java
    Replies: 0
    Last Post: 03-12-2008, 12:03 PM
  4. Jsp and javascript
    By Ed in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-04-2007, 05:54 AM
  5. javascript validation
    By yuchuang in forum New To Java
    Replies: 5
    Last Post: 05-14-2007, 04:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •