Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help Feedback/Survey Script

    Hi,

    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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    De gustibus non est disputandum.

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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.
    OracleGuy

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <html>
    <head>
    <title>Survey</title>
    <script>
    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);
    			num++;
    		}
    	}
    
    	form.average.value = (sum / num);
    	
    	alert(form.average.value );
    	return false;
    }
    
    </script>
    </head>
    
    <body>
    
    <form name="survey" onsubmit="return calculateAverage(this);">
    <input type="hidden" name="average" />
    
    <div>
    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 />
    </div>
    
    <div>
    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 />
    </div>
    
    <div>
    <input type="submit" />
    </div>
    </form>
    Last edited by mordred; 10-07-2003 at 11:56 PM.
    De gustibus non est disputandum.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    De gustibus non est disputandum.


  •  

    Posting Permissions

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