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 Jscript for risk calculator

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:20 PM PM User | #1 tim_k New Coder   Join Date: May 2013 Posts: 10 Thanks: 0 Thanked 0 Times in 0 Posts Jscript for risk calculator 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?
 06-14-2013, 01:04 PM PM User | #2 rohansharma New to the CF scene   Join Date: Jun 2013 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts If you have any doubt you can ask at https://www.udemy.com/java-basics-fo...de=techdisfree. Just join their free online java course and solve your problem.
 06-14-2013, 06:21 PM PM User | #3 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,603 Thanks: 4 Thanked 2,598 Times in 2,567 Posts JScript is not a form of java. Moving to the Javascript forum. __________________ PHP Code: ``` header('HTTP/1.1 420 Enhance Your Calm');  ```
 06-14-2013, 07:03 PM PM User | #4 Philip M Supreme Master coder!     Join Date: Jun 2002 Location: London, England Posts: 17,486 Thanks: 200 Thanked 2,470 Times in 2,448 Posts The Javascript (not Java or Jscript) syntax is if ((x==1) && (y==1) && && (z==1)) {output = "Risk Combo 1"} But I am confused. You say that input y consists of three options, a, b and c, so where do 1, 2 and 3 come from? Are these radio buttons? You say input z has values "yes" and "no", not 1 and 2. As an example, you want something like this:- Code: ```
SIZE 0-7mm SIZE 7-10mm SIZE over 10mm

LOCATION A LOCATION B LOCATION C

YES NO

THE RESULT ``` Quizmaster: Manchuria is a historic region of which country? Contestant: France __________________ All the code given in this post has been tested and is intended to address the question asked. Unless stated otherwise it is not just a demonstration.
06-14-2013, 08:47 PM   PM User | #5
Old Pedant
Supreme Master coder!

Join Date: Feb 2009
Posts: 24,952
Thanks: 75
Thanked 4,308 Times in 4,275 Posts
Pardon me, but just a *TINY* bit of SIMPLE arithmetic analysis allows us to see that all of *THIS*:
Quote:
 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
Can be condensed down to just this:
Code:
`output( RiskCombo[ x + (y-1) * 3 + (z-1) * 9 ] );`
So if you put all the RiskCombo outputs into a simple array:
Code:
```var RiskCombos = [
"You are at very low risk; go enjoy life",
"You need to be careful with that aneurysm",
...
"You are going to die in 17 seconds"
];```
Then you could do something like:
Code:
```<div id="message"></div>
...
document.getElementById("message").innerHTML =
RiskCombos[  (x - 1) + (y-1) * 3 + (z-1) * 9 ];```
(We use (x-1) because the array elements are numbered 0 to 17, not 1 to 18.)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

 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 07:21 PM.