Welcome to the LimeSurvey Community Forum

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

Delete select options (dropdown list) via java script

  • jonaskoeppel
  • jonaskoeppel's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago - 10 years 10 months ago #102715 by jonaskoeppel
Hi everyone,
I've got a quick question which is probably not a big deal but is breaking my nerve.

I'm trying to implement two cascading dropdown lists (the answer options of the second depend on the answer of the first ...). I found several threads in the forum regarding this question but the simplest solution seemed the one in the LS manual:

www.limesurvey.org/manual/Workarounds:_M..._Javascript#Method_2

So far so good. The only problem: it doesn't work. The java script runs properly (tested with alert()) but it won't remove the answer options. Anyone has an idea why this doesn't work?

I also tried the following to test it but it didn't work eighter.

$('#answer' + '{ID.sgqa}').click(function(){
$("#jquery-select option[value='test_value']").remove();
});

Some help would be much appreciated, thanks a lot in advance! Thanks in general for the great work of the developpers!

Jonas
Last edit: 10 years 10 months ago by jonaskoeppel.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
10 years 10 months ago - 8 years 7 months ago #102718 by DenisChenu
Hi Jonas,

I do a complet javascript file for 1.92:
demonstration.sondages.pro/upload/templa...nade/selectfilter.js

I didn't test on 2.0, but can do the trick, think it work too.

The 2 question need to be in same group
demonstration.sondages.pro/82885/lang-fr

PS: script work without update in 2.00
limesurvey.sondages.pro/survey/index/sid...85/newtest/Y/lang/fr
Code:
<script type="text/javascript" src="https://demonstration.sondages.pro/upload/templates/select_filter_citronade/selectfilter.js"></script>
<script type="text/javascript" charset="utf-8">
selectFilterByCode({QID},{SECTION.qid});
</script>

For 2.5:

deejroamer wrote: @DenisChenu, Thank you for your amazing out of the box script. I just modded it a bit so that the CSS of the new select is same as it was for the original select.

Link Here

I am not sure how long link will be up so To do the same

Add this line

Code:
var classSelectFilter = $("#question"+qID).find("select").attr('class');

Mod this line
Code:
var NewSelectElement = "<select id='"+idNewSelectFilter+"' class='"+classSelectFilter+"'><option value=''>"+$("#"+idSelectFilter+" option[value='']:first").text()+"</option></select>";


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: 8 years 7 months ago by DenisChenu. Reason: Add 2.50
The following user(s) said Thank You: rquirola
The topic has been locked.
  • jonaskoeppel
  • jonaskoeppel's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #102722 by jonaskoeppel
Well, well, that's all I could ever hope for, or even more.. And that in no time. Thank you very much!

Great work, keep going like this!

Jonas

PS: Denis, j'ai constaté que tes réponses sont plus rapides au forum que par mail, peut-être c'est par ce moyen que je t'écrivrai au prochainement ;)
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
10 years 10 months ago #102724 by DenisChenu

jonaskoeppel wrote: PS: Denis, j'ai constaté que tes réponses sont plus rapides au forum que par mail, peut-être c'est par ce moyen que je t'écrivrai au prochainement ;)

Non,

Je prend pas plus de 3 minutes par poste sur le forum ... et encore ...

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.
  • jonaskoeppel
  • jonaskoeppel's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #102739 by jonaskoeppel
I tested the script, works like a charm (why shouldn't it ..).

Now I have one last question: can I extend it in an easy way to a higher (for instance third) level? Meaning instead of just comparing the first character, I want to compare the first and the second:

First level: A, B, ...
Second level: A1, A2, B1, B2, ...
Third level: A1a, A1b, A2a, A2b, B1a, B1b, B2a, B2b, ...

Thanks already for your help.

Jonas
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
10 years 10 months ago #102749 by DenisChenu
Hi,

Think you can without updating the script.
But you have to use 2 times the function.

If it was Q1,Q2,Q3:

In Q2:
selectFilterByCode({QID},{Q1.qid});
and in Q3
selectFilterByCode({QID},{Q2.qid});

There are a fix for "select empry in first Question to do:
You have to add a line after line 44:
Code:
$('#'+idSelectFilter).trigger('change');
If there are condition on this question.

Denis

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.
  • jonaskoeppel
  • jonaskoeppel's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #102890 by jonaskoeppel
Perfect! Thanks a lot Denis!

A quick suggestion: maybe you could replace the work around in the manual ( www.limesurvey.org/manual/Workarounds:_M..._Javascript#Method_2 ) with your method, since yours is a lot more sophisticated and works out of the box. That way others won't have to search the forums..

Wish you nice holidays!

Jonas
The topic has been locked.
More
10 years 2 months ago - 10 years 2 months ago #112372 by ongkichilam
Help!
I wanted to implement this I don't understand how Denis managed to include the script just for a specific question.
His solution is so neat but does it appear only under div id = question18699 ?
Last edit: 10 years 2 months ago by ongkichilam. Reason: typo
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
10 years 2 months ago #112374 by DenisChenu
Hi,

You have to put the script in question text source (or help).
www.limesurvey.org/manual/Workarounds:_M....29_in_LimeSurvey.3F

{QID} is replaced by actual question id, then no need to update.
{Q1.qid} is replacxed by the id of Q1 question code.

Denis

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.
More
10 years 2 months ago #112375 by ongkichilam
Like this?

{if(QID=='894', "<script type='text/javascript' src='{TEMPLATEURL}selectfilter.js'></script><script type='text/javascript' charset='utf-8'>selectFilterByCode(894,895);</script>", "")}
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
10 years 2 months ago #112376 by DenisChenu
Why put if ?

You put this in question 894 source, not elsewhere.

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.
More
10 years 2 months ago #112378 by ongkichilam
Looks like I am missing something.... where exactly is the 'question source'?
I did that at templates/question.pstpl :(
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose