Welcome to the LimeSurvey Community Forum

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

Question about javascript

More
10 years 3 weeks ago #132067 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.
More
10 years 3 weeks ago #132073 by DenisChenu
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 support - Plugins, theme and development .
I don't answer to private message.
The following user(s) said Thank You: mmoret
The topic has been locked.
More
10 years 3 weeks 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.
More
10 years 3 weeks ago - 10 years 3 weeks ago #132080 by DenisChenu
Ah OK, but here :

You don't need any JS :
Add it in you url : if question code is SATISFIED :
/SATISFIED/Y (see www.limesurvey.org/manual/URL_fields#Pre...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 support - Plugins, theme and development .
I don't answer to private message.
Last edit: 10 years 3 weeks ago by DenisChenu.
The following user(s) said Thank You: mmoret
The topic has been locked.
More
10 years 3 weeks 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.
More
10 years 3 weeks 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.
More
10 years 3 weeks 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.
More
10 years 3 weeks 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.
More
10 years 3 weeks 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.
More
10 years 3 weeks 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.
More
10 years 2 weeks 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.
More
10 years 2 weeks ago #132334 by DenisChenu

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 support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose