Delete select options (dropdown list) via java script

More
3 years 3 months ago - 3 years 3 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:

manual.limesurvey.org/Workarounds:_Manip..._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: 3 years 3 months ago by jonaskoeppel.

Please Log in to join the conversation.

More
3 years 3 months ago - 1 year 5 days 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
<script type="text/javascript" src="http://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

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

Mod this line
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 service on demand (or search sondages pro).
Last Edit: 1 year 5 days ago by DenisChenu. Reason: Add 2.50
The following user(s) said Thank You: rquirola

Please Log in to join the conversation.

More
3 years 3 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 ;)

Please Log in to join the conversation.

More
3 years 3 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 service on demand (or search sondages pro).

Please Log in to join the conversation.

More
3 years 3 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

Please Log in to join the conversation.

More
3 years 3 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:
$('#'+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 service on demand (or search sondages pro).

Please Log in to join the conversation.

More
3 years 2 months ago #102890 by jonaskoeppel
Perfect! Thanks a lot Denis!

A quick suggestion: maybe you could replace the work around in the manual ( manual.limesurvey.org/Workarounds:_Manip..._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

Please Log in to join the conversation.

More
2 years 6 months ago - 2 years 6 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: 2 years 6 months ago by ongkichilam. Reason: typo

Please Log in to join the conversation.

More
2 years 6 months ago #112374 by DenisChenu
Hi,

You have to put the script in question text source (or help).
manual.limesurvey.org/Workarounds:_Manip....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 service on demand (or search sondages pro).

Please Log in to join the conversation.

More
2 years 6 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>", "")}

Please Log in to join the conversation.

More
2 years 6 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 service on demand (or search sondages pro).

Please Log in to join the conversation.

More
2 years 6 months ago #112378 by ongkichilam
Looks like I am missing something.... where exactly is the 'question source'?
I did that at templates/question.pstpl :(

Please Log in to join the conversation.

More
2 years 6 months ago #112379 by ongkichilam
AH! I found it! Place it at the editor itself!
Thanks~! Works perfectly!

Please Log in to join the conversation.

More
2 years 6 months ago #112384 by ongkichilam
No, {Q1.qid} became 'Undefined variable'.

Appreciate your swift response, Denis.

Please Log in to join the conversation.

More
2 years 6 months ago #112395 by DenisChenu
Q1 must be replaced by the first question code.

Updated exemple survey to show question code and the script.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.