- Posts: 13
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Input default answers (numerical values) to array (numbers) with text input
- Sev
- Topic Author
- Offline
- New Member
Less
More
9 years 4 weeks ago #118453
by Sev
Input default answers (numerical values) to array (numbers) with text input was created by Sev
Hello,
Is there a way to input default numerical values as answers of an Array (Numbers) with text inputs?
Something like this? Trying to input default values of 0 for each answer cell... (although this one does not work)
Thank you in advance for any tip!
Is there a way to input default numerical values as answers of an Array (Numbers) with text inputs?
Something like this? Trying to input default values of 0 for each answer cell... (although this one does not work)
Code:
<script type="text/javascript"> $(document).ready(function() { $('#answer442200X4X2S1_Cost1').val('0'); $('#answer442200X4X2S2_Cost1').val('0'); $('#answer442200X4X2S3_Cost1').val('0'); $('#answer442200X4X2S1_Cost2').val('0'); $('#answer442200X4X2S2_Cost2').val('0'); $('#answer442200X4X2S3_Cost2').val('0'); }); </script>
Thank you in advance for any tip!
The topic has been locked.
- Sev
- Topic Author
- Offline
- New Member
Less
More
- Posts: 13
- Thank you received: 0
9 years 4 weeks ago #118504
by Sev
Replied by Sev on topic Input default answers (numerical values) to array (numbers) with text input
Actually it works, sorry, I had a filter on that did not let me see the answer.
Also I did not think I would be able to write a readily working script
Also I did not think I would be able to write a readily working script
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
9 years 4 weeks ago #118524
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Input default answers (numerical values) to array (numbers) with text input
I think you want to test to make sure the input is empty before loading the default:
Or, if you want to set defaults for all inputs in the question, simplify it with a loop:
Code:
<script type="text/javascript"> $(document).ready(function() { if($('#answer442200X4X2S1_Cost1').val() == '') { $('#answer442200X4X2S1_Cost1').val('0'); } if($('#answer442200X4X2S2_Cost1').val() == '') { $('#answer442200X4X2S2_Cost1').val('0'); } if($('#answer442200X4X2S3_Cost1').val() == '') { $('#answer442200X4X2S3_Cost1').val('0'); } if($('#answer442200X4X2S1_Cost2').val() == '') { $('#answer442200X4X2S1_Cost2').val('0'); } if($('#answer442200X4X2S2_Cost2').val() == '') { $('#answer442200X4X2S2_Cost2').val('0'); } if($('#answer442200X4X2S3_Cost2').val() == '') { $('#answer442200X4X2S3_Cost2').val('0'); } }); </script>
Or, if you want to set defaults for all inputs in the question, simplify it with a loop:
Code:
<script type="text/javascript"> $(document).ready(function() { // Loop through all inputs in this question $('#question{QID} input[type="text"]').each(function(i) { if($(this).val() == '') { $(this).val('0'); } }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Sev
- Topic Author
- Offline
- New Member
Less
More
- Posts: 13
- Thank you received: 0
9 years 3 weeks ago #118556
by Sev
Replied by Sev on topic Input default answers (numerical values) to array (numbers) with text input
That's very useful, thank you very much for your reply!
The topic has been locked.