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

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

Re: Validation for only one of the answers in multiple short text question 2 years 5 months ago #68113

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
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.

Re: Validation for only one of the answers in multiple short text question 2 years 5 months ago #68125

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 170
  • 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: 2 years 5 months ago by waitz.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.113 seconds
Donation Image