Welcome to the LimeSurvey Community Forum

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

Question about javascript

  • mmoret
  • mmoret's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132067 by mmoret
Question about javascript was created by mmoret
Hi,
I want to do a automatically submit whem a yes/no field is Yes.
We sent the Yes/no with the url.
It is some sort of one-click satisfied option.

I now have the following javascript, but does not seem to work. I tried cheanging the "Yes" to "Y".

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
if ("{INSERTANS:OneClick}" == "Yes")
$('#movesubmitbtn').click();
});
</script>

Any help?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #132073 by DenisChenu
Replied by DenisChenu on topic Question about javascript
Hi,

You need to do an action ON event
Code:
$(document).on("click","#answer{SQA}-Y",function(){
$('#movesubmitbtn').click();
});
See api.jquery.com/on/

Code to be put in the question text

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: mmoret
The topic has been locked.
  • mmoret
  • mmoret's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132074 by mmoret
Replied by mmoret on topic Question about javascript
Hi,
Do I even need to do that when I set the Yes via the URL?
The question is hidden. So no one will click...

Regards,
Martijn
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago - 8 years 1 month ago #132080 by DenisChenu
Replied by DenisChenu on topic Question about javascript
Ah OK, but here :

You don't need any JS :
Add it in you url : if question code is SATISFIED :
/SATISFIED/Y (see manual.limesurvey.org/URL_fields#Prefill...using_GET_parameters )

If the question is hidden (by limesurvey attribute) it don't show . demonstration.sondages.pro/462547/SATISFIED/Y/newtest/Y#

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 8 years 1 month ago by DenisChenu.
The following user(s) said Thank You: mmoret
The topic has been locked.
  • mmoret
  • mmoret's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132105 by mmoret
Replied by mmoret on topic Question about javascript
Hi,

I know how to set the answer, I want to submit the form when Yes is passed through via the url.

Regards,
Martijn
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #132129 by tpartner
Replied by tpartner on topic Question about javascript
Try this (untested):

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {
    if($('#answer{SQA}-Y').is(':checked')) {
      $('#movesubmitbtn').trigger('click');
    }
  });
</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: mmoret
The topic has been locked.
  • mmoret
  • mmoret's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132171 by mmoret
Replied by mmoret on topic Question about javascript
Hi,
I have tried your code. Thanks!
However, I do not see the code in my source on the survey.
The hidden question is not visible in the code, so I think the javascript is not executed.

You can check this url:
d-mp.limequery.com/index.php/survey/inde...verall=A4&OneClick=Y

Thanks!
Martijn
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #132172 by tpartner
Replied by tpartner on topic Question about javascript
You cannot use JavaScript in a question that is hidden with the advanced question setting - that question is never rendered in the HTML so JavaScript cannot work. Instead, hide the question with CSS or JavaScript.

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {
    $('#question{QID}').hide();
 
    if($('#answer{SQA}-Y').is(':checked')) {
      $('#movesubmitbtn').trigger('click');
    }
  });
</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: mmoret
The topic has been locked.
  • mmoret
  • mmoret's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132176 by mmoret
Replied by mmoret on topic Question about javascript
Hi,

Thanks for your quick replies!
I really appreciate your support!

I am getting there, the script code is there, but some rendering is happening:
<div id="question653" class="yes-no">
<table class="question-wrapper">
<tr>
<td align="center">
<table width="100%" cellspacing="0">
<tr>
<td class="question-text">
<span class="asterisk"></span><span class="qnumcode"> </span>OneClick

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#question653').hide();

if ($('#answer<span style='background-color: #eee8aa;'><span title='Undefined variable' style='border-style: solid; border-width: 2px; border-color: red;'><span title='Undefined variable' style='color: red; font-weight: bold'>SQA</span></span></span>-Y').is(':checked')) {
$('#movesubmitbtn').trigger('click');
}
});
</script>

I have added a space after if and check Filter HTMl on XSS is set to No.
Regards,
Martijn
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #132185 by tpartner
Replied by tpartner on topic Question about javascript
Oops, that was a typo using Denis' code :blush:

Try this:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {
    $('#question{QID}').hide();
 
    if($('input.radio[id$="X{QID}Y"]').is(':checked')) {
       $('#movesubmitbtn').trigger('click');
    }
  });
</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: mmoret
The topic has been locked.
  • mmoret
  • mmoret's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 1 month ago #132219 by mmoret
Replied by mmoret on topic Question about javascript
Hi all,

This works great!!!
Thanks for your support and suggestions.

Regards,
Martijn
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #132334 by DenisChenu
Replied by DenisChenu on topic Question about javascript

tpartner wrote: Oops, that was a typo using Denis' code :blush:

:blush: :whistle: i never test script in forum ;)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose