/    Sign up×
Community /Pin to ProfileBookmark

I created a survey and I need help making functions for it. I haven’t created a function yet because I obviously don’t know how to do it well yet. . I want the function to add 5 points for every A answer, 4 for for every B, 3 for C, 2 for D and 1 for the radio buttons. Also I want it to give a +1 score to every checkbox in question 5. For the last two questions I would like to create a function that will make the middle value +2 of the select objects, +1 for the second and fourth choices, and 0 for the first or fifth. Finally have all of these add up into the wellnes rating textbox.

Here is my outline of the code without the javascript added yet:

<head>
<title> Wellness Exam </title></head>

<center><h1> How Healthy Are You, Really? </h1>
<center><h2> The Results May Shock You </h2>

<body>
<form id=”survey” name=”survey”>
<p align=left>

<strong>1. Which one of the five choices best describes how often a week you exercise? </strong> <br><br>
<input type=”radio” name=”exercise” /> 6 or 7 <br>
<input type=”radio” name=”exercise” /> 4 or 5 <br>
<input type=”radio” name=”exercise” /> 2 or 3 <br>
<input type=”radio” name=”exercise” /> 1 <br>
<input type=”radio” name=”exercise” /> 0 <br>
<br>

<strong>2. Which one of these describes how many fast food meals you eat in a week? </strong><br><br>
<input type=”radio” name=”fastfood” /> 0 <br>
<input type=”radio” name=”fastfood” /> 1 to 3 <br>
<input type=”radio” name=”fastfood” /> 4 to 6 <br>
<input type=”radio” name=”fastfood” /> 7 to 9 <br>
<input type=”radio” name=”fastfood” /> More than 9 <br>
<br>

<strong>3. How many portions of fresh fruit of vegetables do you eat in a week? </strong> <br>
<input type=”radio” name=”fruit” /> Ten or more <br>
<input type=”radio” name=”fruit” /> 7 to 9 <br>
<input type=”radio” name=”fruit” /> 5 to 6 <br>
<input type=”radio” name=”fruit” /> 2 to 4 <br>
<input type=”radio” name=”fruit” /> one or less <br>
<br>

<strong>4.How often do you do your Web Page homework in a week? </strong> <br>
<input type=”radio” name=”homework” /> More than 5 <br>
<input type=”radio” name=”homework” /> 4 to 5 <br>
<input type=”radio” name=”homework” /> 3 <br>
<input type=”radio” name=”homework” /> 1 to 2 <br>
<input type=”radio” name=”homework” /> Zero <br>
<br>

<strong>5. Select the best courses you have taken: </strong><br>
<input type=”checkbox”> Web Design <br>
<input type=”checkbox”> Computer Operating Systems <br>
<input type=”checkbox”> Java Programming <br>
<br>

<strong>6. How much beer do you consume in a week? </strong> <br>
<select name=”beerconsumption”>
<option>None</option>
<option>1-2</option>
<option>3-5</option>
<option>6-9</option>
<option>10 or more</option></select>
<br><br>

<strong>7. How many glasses of red wine do you consume in a week? </strong> <br>
<select name=”wineconsumption”>
<option>None</option>
<option>1-2</option>
<option>3-5</option>
<option>6-9</option>
<option>10 or more</option></select>
<br><br>

</form>

<form id=maximum name=maximum>

<input type=button name=butt1 value=”Take a Deep Breath” onclick=maxcalc()><br>

<textarea rows=10 cols=50 name=outarea></textarea><br>Your Wellness Rating Message </a>

</form>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mlimDec 13.2006 — Try this :



<head>

<title> Wellness Exam </title></head>

<script type="text/javascript">

var Total;

function ClearBox(){

var box1 = document.getElementById("outarea");

box1.value="";

for (i=0;i<document.survey.exercise.length;i++){

if (document.survey.exercise[i].checked==true) document.survey.exercise[i].checked=false

}



for (i=0;i<document.survey.fastfood.length;i++){

if (document.survey.fastfood[i].checked==true) document.survey.fastfood[i].checked=false

}



for (i=0;i<document.survey.fruit.length;i++){

if (document.survey.fruit[i].checked==true) document.survey.fruit[i].checked=false

}



for (i=0;i<document.survey.homework.length;i++){

if (document.survey.homework[i].checked==true) document.survey.homework[i].checked=false

}



for (i=0;i<document.survey.courses.length;i++){

if (document.survey.courses[i].checked==true) document.survey.courses[i].checked=false

}



}





function maxcalc() {



var r0=r1=r2=r3=r4=0;



//a variable that will hold the index number of the selected radio button



for (i=0;i<document.survey.exercise.length;i++){

if (document.survey.exercise[i].checked==true)

r0=5-i

}



for (i=0;i<document.survey.fastfood.length;i++){

if (document.survey.fastfood[i].checked==true)

r1=5-i

}



for (i=0;i<document.survey.fruit.length;i++){

if (document.survey.fruit[i].checked==true)

r2=5-i

}



for (i=0;i<document.survey.homework.length;i++){

if (document.survey.homework[i].checked==true)

r3=5-i

}



for (i=0;i<document.survey.courses.length;i++){

if (document.survey.courses[i].checked==true)

r4=r4+i+1

}



Total = r0 + r1 + r2 + r3 + r4;

alert("Well Done");



document.getElementById("outarea").innerHTML = "Well Done "+r0+" "+r1+" "+r2+" "+r3+" "+r4+" Total = "+Total;



}

</script>

</head>





<body>

<center><h1> How Healthy Are You, Really? </h1>

<center><h2> The Results May Shock You </h2>



<form id="survey" name="survey">

<p align=left>



<strong>1. Which one of the five choices best describes how often a week you exercise? </strong> <br><br>

<input type="radio" name="exercise" /> 6 or 7 <br>

<input type="radio" name="exercise" /> 4 or 5 <br>

<input type="radio" name="exercise" /> 2 or 3 <br>

<input type="radio" name="exercise" /> 1 <br>

<input type="radio" name="exercise" /> 0 <br>

<br>



<strong>2. Which one of these describes how many fast food meals you eat in a week? </strong><br><br>

<input type="radio" name="fastfood" /> 0 <br>

<input type="radio" name="fastfood" /> 1 to 3 <br>

<input type="radio" name="fastfood" /> 4 to 6 <br>

<input type="radio" name="fastfood" /> 7 to 9 <br>

<input type="radio" name="fastfood" /> More than 9 <br>

<br>



<strong>3. How many portions of fresh fruit of vegetables do you eat in a week? </strong> <br>

<input type="radio" name="fruit" /> Ten or more <br>

<input type="radio" name="fruit" /> 7 to 9 <br>

<input type="radio" name="fruit" /> 5 to 6 <br>

<input type="radio" name="fruit" /> 2 to 4 <br>

<input type="radio" name="fruit" /> one or less <br>

<br>



<strong>4.How often do you do your Web Page homework in a week? </strong> <br>

<input type="radio" name="homework" /> More than 5 <br>

<input type="radio" name="homework" /> 4 to 5 <br>

<input type="radio" name="homework" /> 3 <br>

<input type="radio" name="homework" /> 1 to 2 <br>

<input type="radio" name="homework" /> Zero <br>

<br>



<strong>5. Select the best courses you have taken: </strong><br>

<input type="checkbox" name="courses" > Web Design <br>

<input type="checkbox" name="courses" > Computer Operating Systems <br>

<input type="checkbox" name="courses" > Java Programming <br>

<br>



<strong>6. How much beer do you consume in a week? </strong> <br>

<select name="beerconsumption">

<option>None</option>

<option>1-2</option>

<option>3-5</option>

<option>6-9</option>

<option>10 or more</option></select>

<br><br>



<strong>7. How many glasses of red wine do you consume in a week? </strong> <br>

<select name="wineconsumption">

<option>None</option>

<option>1-2</option>

<option>3-5</option>

<option>6-9</option>

<option>10 or more</option></select>

<br><br>



</form>



<form id="maximum" name="maximum">



<input type="button" name="butt1" value="Take a Deep Breath" onclick="maxcalc()"><br>



<textarea rows="10" cols="50" name="outarea"></textarea><br>Your Wellness Rating Message &nbsp; &nbsp



<input type="button" name="Reset" value="Reset" onclick="ClearBox()"><br>

</form>

</body>
Copy linkTweet thisAlerts:
@dkizzyauthorDec 13.2006 — thanks, I guess my function was a little more basic since I'm a newb but I reposted it and if you can help me by either replying on this post or the new one I'd like the survey results to be added to an email and then designating an email to send them to.
×

Success!

Help @dkizzy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...