Welcome, Guest
Username: Password: Remember me

TOPIC: Delete select options (dropdown list) via java script

Delete select options (dropdown list) via java script 3 months 3 weeks ago #102715

  • jonaskoeppel
  • jonaskoeppel's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
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 months 3 weeks ago by jonaskoeppel.
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 3 months 3 weeks ago #102718

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 5830
  • Thank you received: 710
  • Karma: 219
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>
Last Edit: 3 months 3 weeks ago by DenisChenu.
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 3 months 3 weeks ago #102722

  • jonaskoeppel
  • jonaskoeppel's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
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 administrator has disabled public write access.

Delete select options (dropdown list) via java script 3 months 3 weeks ago #102724

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 5830
  • Thank you received: 710
  • Karma: 219
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 ...
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 3 months 3 weeks ago #102739

  • jonaskoeppel
  • jonaskoeppel's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
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 administrator has disabled public write access.

Delete select options (dropdown list) via java script 3 months 3 weeks ago #102749

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 5830
  • Thank you received: 710
  • Karma: 219
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
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 3 months 3 weeks ago #102890

  • jonaskoeppel
  • jonaskoeppel's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
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
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.216 seconds
Donation Image