Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Send survey result to email address depending on answer to question

  • sdoyle
  • sdoyle's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 5 months ago #100568 by sdoyle
I have a survey that has a dropdown question (Q1) School Name with Answers such as A1: NewSchool - NewTown and A2: OldSchool - OldTown. I need to use the answer to Q1 to send the submitted survey to the relevant School Principal via email. The person submitting the survey won't know the email address. How can I link A1 to principal@schooldomain.edu?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 5 months ago #100595 by tpartner
You can:

1) Add a short-text question right after the drop-down (it must be on the same page)

2) Set up your survey to use JavaScript .

3) Add the script below to the question source of the drop-down. This script will:
- Hide the short-text
- Load the short-text with email addresses depending on the selection in the drop-down

4) Set your notification to use the value in the short-text - manual.limesurvey.org/Creating_a_new_sur..._.26_data_management

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    var thisQuestion = $('#question{QID}');
    var emailQuestion = $(thisQuestion).nextAll('.text-short:eq(0)');
 
    // Hide the email address question
    $(emailQuestion).hide();
 
    // Listener on the dropdown
    $('select', thisQuestion).change(function(event) {
 
      // Define the email address
      var emailAddress = '';
      switch($(this).val()) {
        case 'A1' :
          emailAddress = 'principal@schooldomain1.edu';
          break;
        case 'A2' :
          emailAddress = 'principal@schooldomain2.edu';
          break;
        case 'A3' :
          emailAddress = 'principal@schooldomain3.edu';
          break;
      }
 
      // Load the hidden email question
      $('input.text', emailQuestion).val(emailAddress);
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: sdoyle
The topic has been locked.
  • sdoyle
  • sdoyle's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 5 months ago #100785 by sdoyle
Excellent, worked a treat :cheer:
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose