Welcome, Guest
Username: Password: Remember me

TOPIC: Determine if current question has already been answered

Determine if current question has already been answered 1 year 11 months ago #88556

In my survey I use JS to autopopulate a question with the user's name using token values. I've realised that if the user hits Next on this page, then returns to it, this JS will overwrite any changes they may have previously made to their name. So I would prefer to autofill the question (short text answer) on page load only if the question has not already been answered.

Below is the script I tried - the trouble is, the answer isn't empty because of something EM is doing. Its value is
<span id='LEMtailor_Q_524_30'></span>
. How can I overcome this?
<script type="text/javascript" charset="utf-8"> 	
	$(document).ready(function() { 
		if("{INSERTANS:48965X62X524}" == "") {
			$('#answer48965X62X524').val('{TOKEN:FIRSTNAME} {TOKEN:LASTNAME}');			
		}
	});
</script>

I'm using the latest Version 1.92+ Build 120919 and my survey is group by group. I haven't yet got around to figuring out EM as I'm trying to resurrect an old survey and get it live as soon as possible.
The administrator has disabled public write access.

Re: Determine if current question has already been answered 1 year 11 months ago #88600

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
I don't know how the value of a text input could be an empty span but try this:
<script type="text/javascript" charset="utf-8"> 	
	$(document).ready(function() { 
		if($('#answer48965X62X524').val() == '') {
			$('#answer48965X62X524').val('{TOKEN:FIRSTNAME} {TOKEN:LASTNAME}');			
		}
	});
</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.
The following user(s) said Thank You: Squirrelicious

Re: Determine if current question has already been answered 1 year 11 months ago #88602

Thanks, Tony! This method does return an empty value.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.185 seconds
Donation Image