Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

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

Delete select options (dropdown list) via java script 2 years 5 months 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: 2 years 5 months ago by jonaskoeppel.
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 2 years 5 months ago #102718

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8927
  • Thank you received: 1249
  • Karma: 371
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>";
Last Edit: 2 months 1 week ago by DenisChenu. Reason: Add 2.50
The administrator has disabled public write access.
The following user(s) said Thank You: rquirola

Delete select options (dropdown list) via java script 2 years 5 months 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 2 years 5 months ago #102724

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8927
  • Thank you received: 1249
  • Karma: 371
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 2 years 5 months 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 2 years 5 months ago #102749

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8927
  • Thank you received: 1249
  • Karma: 371
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 2 years 5 months 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.

Delete select options (dropdown list) via java script 1 year 8 months ago #112372

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: 1 year 8 months ago by ongkichilam. Reason: typo
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 1 year 8 months ago #112374

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8927
  • Thank you received: 1249
  • Karma: 371
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
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 1 year 8 months ago #112375

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 administrator has disabled public write access.

Delete select options (dropdown list) via java script 1 year 8 months ago #112376

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8927
  • Thank you received: 1249
  • Karma: 371
Why put if ?

You put this in question 894 source, not elsewhere.
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 1 year 8 months ago #112378

Looks like I am missing something.... where exactly is the 'question source'?
I did that at templates/question.pstpl :(
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 1 year 8 months ago #112379

AH! I found it! Place it at the editor itself!
Thanks~! Works perfectly!
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 1 year 8 months ago #112384

No, {Q1.qid} became 'Undefined variable'.

Appreciate your swift response, Denis.
The administrator has disabled public write access.

Delete select options (dropdown list) via java script 1 year 8 months ago #112395

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8927
  • Thank you received: 1249
  • Karma: 371
Q1 must be replaced by the first question code.

Updated exemple survey to show question code and the script.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.279 seconds