Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Medical risk calculator - three inputs

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 05-18-2013, 03:26 PM PM User | #1 tim_k New Coder   Join Date: May 2013 Posts: 10 Thanks: 0 Thanked 0 Times in 0 Posts Medical risk calculator - three inputs Hi all, I'm trying my hand at jscript for the first time (au fait with html and css). I'd like to build a medical risk calculator to sit in a side block on a drupal site. The html form is done. Input x is the size of an aneurysm and input will be in text and then parsed into ranges (0-7mm, 7-10mm and 10+mm) Input y is location of aneurysm and consists of three options, a, b & c. Input z is yes / no radio button Output (risk) should update each time input is changed (no submit button). Each combination of these variables should produce two linked risk values (% in one year and % in five years). The number of potential outputs is thus 3x3x2 = 18 (so it's not really a calculation, more a lookup). I am imagining some sort of 18-faceted list of functions like this: If x=1 AND y=1 AND z=1 THEN output Risk combo 1 IF x=2 AND y=1 AND z=1 THEN output Risk combo 2 IF x=3 AND y=1 AND z=1 THEN output Risk combo 3 IF x=1 AND y=2 AND z=1 THEN output Risk combo 4 IF x=2 AND y=2 AND z=1 THEN output Risk combo 5 IF x=3 AND y=2 AND z=1 THEN output Risk combo 6 IF x=1 AND y=3 AND z=1 THEN output Risk combo 7 IF x=2 AND y=3 AND z=1 THEN output Risk combo 8 IF x=3 AND y=3 AND z=1 THEN output Risk combo 9 If x=1 AND y=1 AND z=2 THEN output Risk combo 10 IF x=2 AND y=1 AND z=2 THEN output Risk combo 11 IF x=3 AND y=1 AND z=2 THEN output Risk combo 12 IF x=1 AND y=2 AND z=2 THEN output Risk combo 13 IF x=2 AND y=2 AND z=2 THEN output Risk combo 14 IF x=3 AND y=2 AND z=2 THEN output Risk combo 15 IF x=1 AND y=3 AND z=2 THEN output Risk combo 16 IF x=2 AND y=3 AND z=2 THEN output Risk combo 17 IF x=3 AND y=3 AND z=2 THEN output Risk combo 18 How should one best go about performing these functions?
05-19-2013, 08:28 AM   PM User | #2
Dormilich
Senior Coder

Join Date: Jan 2010
Location: Behind the Wall
Posts: 3,086
Thanks: 11
Thanked 327 Times in 323 Posts
since you mentioned a lookup-table, what about a nested Array?
PHP Code:
``` // though you need to use a 0-based index in your <input>svar risks = [ // x-level    [ // y-level        [risk combo 1, risk combo 2], // z-level        [risk combo 3, risk combo 4],        [risk combo 5, risk combo 6]    ],    [        [risk combo 7, risk combo 8],        [risk combo 9, risk combo 10],        [risk combo 11, risk combo 12]    ],    [        [risk combo 13, risk combo 14],        [risk combo 15, risk combo 16],        [risk combo 17, risk combo 18]    ]]// access would work like// remember, it's zero-indexedvar combo = risks[x][y][z];  ```
__________________
Quote:
 The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
André Behrens, NY Times Software Developer

Last edited by Dormilich; 05-19-2013 at 08:32 AM..

 05-19-2013, 03:18 PM PM User | #3 tim_k New Coder   Join Date: May 2013 Posts: 10 Thanks: 0 Thanked 0 Times in 0 Posts Thanks for your suggestion - will read around this approach and give it a try!
05-19-2013, 03:34 PM   PM User | #4
Dormilich
Senior Coder

Join Date: Jan 2010
Location: Behind the Wall
Posts: 3,086
Thanks: 11
Thanked 327 Times in 323 Posts
if you don’t have numbers as input value, you could do the same with an object.
PHP Code:
``` var risks = {  "category 1": {    "class 1" : {      "subclass 1": "combo 1",      "subclass 2": "combo 2"    // etc.    },    "class 2" : {      // etc.    }  },  "category 2": {    // etc.  }};  ```
__________________
Quote:
 The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
André Behrens, NY Times Software Developer

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 11:36 PM.