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

TOPIC: Validation for only one of the answers in multiple short text question

Validation for only one of the answers in multiple short text question 3 years 10 months ago #68113

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5087
  • Thank you received: 1046
  • Karma: 438
I don't think you are using the correct input IDs. I think you need to append "comment" to them.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		maxChars($("#answer68164X55X913ref01comment"), 80, 'The answer can only be a maximum of 80 characters.');
		maxChars($("#answer68164X55X913ref02comment"), 80, 'The answer can only be a maximum of 80 characters.');
 
		function maxChars(inputID, maxNum, msg) {
 
			if($(inputID).length > 0) {
 
				// Interrupt next/submit function 
				$('#movenextbtn, #movesubmitbtn').click(function(){
 
					if($(inputID).val().length > maxNum) {
						$(inputID).addClass('maxCharsError');
						alert (msg);
						return false;
					}
					else {
						$(inputID).removeClass('maxCharsError');
						return true;
					}
				});
			}
		}
	});
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Validation for only one of the answers in multiple short text question 3 years 9 months ago #68125

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Yepp, of course. And I could have seen the inputID with firebug, I realize. I will look there first next time.

Thanks again, though :)
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Last Edit: 3 years 9 months ago by waitz.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.139 seconds