- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array (texts) and default value change with onclick?
- Raymond1612
- Topic Author
- Offline
- New Member
Less
More
1 year 6 months ago #232712
by Raymond1612
Array (texts) and default value change with onclick? was created by Raymond1612
Hello. I am looking for help with the following:
I have a "Array (texts)" question with numbers only for which I use an javascript to set the default value to 0:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var defaultText = '0';
$('#question{QID} tr[id^="javatbd"] input:text').each(function(i) {
if($(this).val() == '') {
$(this).val(defaultText)
}
});
});
</script>
That's working fine, but I want the default value to be cleared once the enduser selects a cell to prevent wrong input.
I am using limesurvey Version 3.15.8+190130
Thanks in advance!
I have a "Array (texts)" question with numbers only for which I use an javascript to set the default value to 0:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var defaultText = '0';
$('#question{QID} tr[id^="javatbd"] input:text').each(function(i) {
if($(this).val() == '') {
$(this).val(defaultText)
}
});
});
</script>
That's working fine, but I want the default value to be cleared once the enduser selects a cell to prevent wrong input.
I am using limesurvey Version 3.15.8+190130
Thanks in advance!
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
1 year 6 months ago #232715
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 Array (texts) and default value change with onclick?
LimeSurvey version?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- Raymond1612
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
1 year 6 months ago #232720
by Raymond1612
Replied by Raymond1612 on topic Array (texts) and default value change with onclick?
I am using limesurvey Version 3.15.8+190130
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
1 year 6 months ago #232727
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 Array (texts) and default value change with onclick?
This script should do the trick:
Sample survey attached:
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var defaultText = '0'; var $inputs = $('#question{QID} tr[id^="javatbd"] input:text'); $inputs.each(function(i) { if($.trim($(this).val()) == '') { $(this).val(defaultText); } }).on('keydown', function(e) { if($.trim($(this).val()) == defaultText) { $(this).val(''); } }).on('keyup change', function(e) { if($.trim($(this).val()) == '') { $(this).val(defaultText); } }); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11660
- Thank you received: 2742
1 year 6 months ago #232736
by holch
You might want to think about updating your installation. Almost 3 years without security patches and bug fixes, just saying.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Array (texts) and default value change with onclick?
I am using limesurvey Version 3.15.8+190130
You might want to think about updating your installation. Almost 3 years without security patches and bug fixes, just saying.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Please Log in to join the conversation.
- Raymond1612
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
1 year 6 months ago #232739
by Raymond1612
Replied by Raymond1612 on topic Array (texts) and default value change with onclick?
The script works perfectly. Thanks for that!
And I'll pass on the message about the update to our administrator.
And I'll pass on the message about the update to our administrator.
Please Log in to join the conversation.