Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

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

Delete select options (dropdown list) via java script 4 Monate 1 Tag her #102715

  • jonaskoeppel
  • jonaskoeppels Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 31
  • Dank erhalten: 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
Letzte Änderung: 4 Monate 1 Tag her von jonaskoeppel.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Delete select options (dropdown list) via java script 4 Monate 1 Tag her #102718

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 5854
  • Dank erhalten: 716
  • Karma: 222
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>
Letzte Änderung: 4 Monate 1 Tag her von DenisChenu.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Delete select options (dropdown list) via java script 4 Monate 22 Stunden her #102722

  • jonaskoeppel
  • jonaskoeppels Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 31
  • Dank erhalten: 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 ;)
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Delete select options (dropdown list) via java script 4 Monate 19 Stunden her #102724

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 5854
  • Dank erhalten: 716
  • Karma: 222
jonaskoeppel schrieb:
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 ...
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Delete select options (dropdown list) via java script 4 Monate 5 Stunden her #102739

  • jonaskoeppel
  • jonaskoeppels Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 31
  • Dank erhalten: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Delete select options (dropdown list) via java script 3 Monate 4 Wochen her #102749

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 5854
  • Dank erhalten: 716
  • Karma: 222
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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Delete select options (dropdown list) via java script 3 Monate 3 Wochen her #102890

  • jonaskoeppel
  • jonaskoeppels Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 31
  • Dank erhalten: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.254 Sekunden
Donation Image