View Full Version : Help Feedback/Survey Script

10-07-2003, 07:45 PM

I need some help on creating a feedback/survey form and I require a JavaScript code, which I am unable to gather together properly. Basically, this is to gather information. This needs to be in JavaScript and Html only as my hosting is not compatible with CGI, ASP, cold fusion, etc...

I have multiple questions, with only for choices for answers. However, these answers all have set values, it's not 1 is right and the other ones are false. It's service wise, here's an example:

1. How was your waiter's speed of service?
A Excellent
B Good
C Fair
D Poor

Now I want to have my choice A to D to have set values such as A=15 B=10 C=5 D=0

Since I would like to receive the total average of my survey sent by email. Therefore I believe that I will need to input a hidden box in my form with the average of the survey so that I could receive it by email.

When I would receive the form in my email from the submit button, I will see what choices the person chose, and I would like to see the total average of his/her result.

Hopefully you can understand what I am searching for, or simply guide me to the right direction on what should I search for.

Thank you

10-07-2003, 09:16 PM
Sending email is outside the domain of JavaScript. You will need a server-side language to do that. And hosting packages including PHP have really dropped to low prices around 1 Euro or sth., so they really are affordable.

10-07-2003, 09:21 PM
thank you for the information.

However, the email option I will keep in my action="mailto section of my page.

What I really need is to know how, get or what I need to search under for a script that will calculate the average of my survey, and I inpute that function to appear in one of my hidden input cell of my form so that way the "customer" will not see it but I will in once I receive the email.

Thank you again.

10-07-2003, 11:20 PM
Using the mailto: in the action requires the user to have a e-mail client installed and configured otherwise it cannot send.

Just be aware of that.

10-08-2003, 12:53 AM
Ok, first I want to point out that I deliberately left out the "mailto:" option in my initial answer because I consider this approach to be very unreliable, because it depends on a lot of issues external to your application (and which all can go wrong). oracleguy pointed out one. Additionally, the user will always see a confirmation message for activating mailto form submits. Put yourself in the user's shoes and think about what he most certainly has read during the MSBlaster worm rage about malicious code... and there is this innocent looking survey which prompts an unknown (and also uncommon) confirmation message... shoud he abort or not... or take the risk... as he did when he opened that email attachment lately...

Also, but only a minor point to consider, is that your form's data will be urlencoded, so you have to decode it once you get the mail. I do only point out these issues because years ago I thought about the same approach as you did, and I decided against it because it essentially was... such a hassle. Got myself a better hosting solution, a tiny PHP script and no hassle anymore.

But apart from that, you asked a genuine javascript question and that deserves to be answered as well. :) So here's a sample code that illustrates how it might work. Basically, you put the ranking numbers into the value attributes and on submittal of the form, you loop through every checked section, add the ranks and calculate the average by dividing through the number of sections which were filled out too, which is been tracked in the "num" variable:

function calculateAverage(form) {
var sum = 0;
var num = 0;
for (var i = 0; i < form.elements.length; i++) {
if (form.elements[i].checked) {
sum += parseInt(form.elements[i].value, 10);

form.average.value = (sum / num);

alert(form.average.value );
return false;



<form name="survey" onsubmit="return calculateAverage(this);">
<input type="hidden" name="average" />

1. How was your waiter's speed of service?<br />
<input type="radio" name="speed" value="15" />A Excellent<br />
<input type="radio" name="speed" value="10" />B Good<br />
<input type="radio" name="speed" value="5" />C Fair<br />
<input type="radio" name="speed" value="0" />D Poor<br />

1. The quality of our wine was..?<br />
<input type="radio" name="wine" value="15" />A Excellent<br />
<input type="radio" name="wine" value="10" />B Good<br />
<input type="radio" name="wine" value="5" />C Fair<br />
<input type="radio" name="wine" value="0" />D Uargh!<br />

<input type="submit" />

10-08-2003, 12:58 AM
Oh, and I forgot to add: The alert() and the "return false" lines are only present for testing/debugging purposes. You need to take them out for your real script in use on your site, or the form won't submit.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum