- Posts: 6
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
If you want to use javascript within Limesurvey you have to disable a security filter before you can add your javascript in source code mode.
* Go to global settings and set the setting 'XSS-Filter' to 'off'.
* Add a new question
* In the question field, expande the tool bar by clicking the upper grey bar to get to the source code editor:
* Click on the button LimeFitWin to get full screen mode with even more buttons in the tool bar:
* Click on the button Source
Now you can add your code. A simple test to see if javascript is enabled is to echo an alert. Use this code to test:
<script type="text/javascript" charset="utf-8">
alert("Test!");
</script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { document.getElementById("answer74931X156X880").value = '{TOKEN:LASTNAME}' }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if('{TOKEN:ATTRIBUTE_2}' == 'VZW') {$("input#answer74931X156X885X1").attr('checked', true);} if('{TOKEN:ATTRIBUTE_2}' == 'FV') {$("input#answer74931X156X885X2").attr('checked', true);} if('{TOKEN:ATTRIBUTE_2}' == 'BVBA') {$("input#answer74931X156X885X3").attr('checked', true);} if('{TOKEN:ATTRIBUTE_2}' == 'NG') {$("input#answer74931X156X885X4").attr('checked', true);} if('{TOKEN:ATTRIBUTE_2}' == 'NV') {$("input#answer74931X156X885X5").attr('checked', true);} if('{TOKEN:ATTRIBUTE_2}' == 'CommV') {$("input#answer74931X156X885X6").attr('checked', true);} if('{TOKEN:ATTRIBUTE_2}' == 'Eenmanszaak') {$("input#answer74931X156X885X7").attr('checked', true);} }); </script>
if('{TOKEN:ATTRIBUTE_3}' == '21' || '{TOKEN:ATTRIBUTE_4}' == '21' || '{TOKEN:ATTRIBUTE_5}' == '21') {$("input#answer74931X156X884X21").attr('checked', true);} if('{TOKEN:ATTRIBUTE_3}' == '22' || '{TOKEN:ATTRIBUTE_4}' == '22' || '{TOKEN:ATTRIBUTE_5}' == '22') {$("input#answer74931X156X884X22").attr('checked', true);} if('{TOKEN:ATTRIBUTE_3}' == '23' || '{TOKEN:ATTRIBUTE_4}' == '23' || '{TOKEN:ATTRIBUTE_5}' == '23') {$("input#answer74931X156X884X23").attr('checked', true);} if('{TOKEN:ATTRIBUTE_3}' == '24' || '{TOKEN:ATTRIBUTE_4}' == '24' || '{TOKEN:ATTRIBUTE_5}' == '24') {$("input#answer74931X156X884X24").attr('checked', true);}
Just give it a try...duvemyster wrote: Should entering {TOKEN:ATTRIBUTE_1} in a default field of a multiple short-text question be working?
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if('{TOKEN:ATTRIBUTE_1}' == 'NSO' && $('#answer38934X2077X29244').val() == '') { $('#answer38934X2077X29244 option').removeAttr('selected'); $('#answer38934X2077X29244 option[value="A1"]').attr('selected', 'selected'); $('#answer38934X2077X29244').val('A1'); } if('{TOKEN:ATTRIBUTE_1}' == 'Academia' && $('#answer38934X2077X29244').val() == '') { $('#answer38934X2077X29244 option').removeAttr('selected'); $('#answer38934X2077X29244 option[value="A2"]').attr('selected', 'selected'); $('#answer38934X2077X29244').val('A2'); } if('{TOKEN:ATTRIBUTE_1}' == 'Private Sector' && $('#answer38934X2077X29244').val() == '') { $('#answer38934X2077X29244 option').removeAttr('selected'); $('#answer38934X2077X29244 option[value="A3"]').attr('selected', 'selected'); $('#answer38934X2077X29244').val('A3'); } if('{TOKEN:ATTRIBUTE_1}' == 'IO' && $('#answer38934X2077X29244').val() == '') { $('#answer38934X2077X29244 option').removeAttr('selected'); $('#answer38934X2077X29244 option[value="A4"]').attr('selected', 'selected'); $('#answer38934X2077X29244').val('A4'); } }); </script>