- Posts: 6
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
if('{TOKEN:ATTRIBUTE_1}' == '1') { ("input#answer74931X156X884A1").attr('checked', true); }
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { if('{TOKEN:ATTRIBUTE_1}' == '1') { ("input#answer74931X156X884A1").attr('checked', true); } }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { ("input#answer74931X156X884A1").attr('checked', true); }); </script>
$("input#answer74931X156X884A1").attr('checked', true);
Maybe make correction to this one:Mazi wrote: Joost, to share your knowledge with other users, ca you write a short tutorial how to prefill different question types like text, single choice, multiple choice, ...?
That would be great!
if('{TOKEN:ATTRIBUTE_3}' == '21') {$("input#answer74931X156X884X21").attr('checked', true);} if('{TOKEN:ATTRIBUTE_3}' == '22') {$("input#answer74931X156X884X22").attr('checked', true);} if('{TOKEN:ATTRIBUTE_3}' == '23') {$("input#answer74931X156X884X23").attr('checked', true);} if('{TOKEN:ATTRIBUTE_4}' == '21') {$("input#answer74931X156X884X21").attr('checked', true);} if('{TOKEN:ATTRIBUTE_4}' == '22') {$("input#answer74931X156X884X22").attr('checked', true);} if('{TOKEN:ATTRIBUTE_4}' == '23') {$("input#answer74931X156X884X23").attr('checked', true);}
if('{TOKEN:ATTRIBUTE_3}' == '21' OR '{TOKEN:ATTRIBUTE_4}' == '21' OF '{TOKEN:ATTRIBUTE_5}' == '21' OR ...) {$("input#answer74931X156X884X21").attr('checked', true);}
It's not jquery, but javascript herejoosts wrote: But I can't find the proper JQUERY syntax for OR statements. Any hints?
if('{TOKEN:ATTRIBUTE_3}' == '21' || '{TOKEN:ATTRIBUTE_4}' == '21' || '{TOKEN:ATTRIBUTE_5}' == '21' ) { $("input#answer74931X156X884X21").attr('checked', true); }
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);}