Determine if current question has already been answered

More
4 years 7 months ago #88556 by Squirrelicious
Squirrelicious created the topic: Determine if current question has already been answered
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.

Please Log in to join the conversation.

More
4 years 7 months ago #88600 by tpartner
tpartner replied the topic: Determine if current question has already been answered
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.
The following user(s) said Thank You: Squirrelicious

Please Log in to join the conversation.

More
4 years 7 months ago #88602 by Squirrelicious
Squirrelicious replied the topic: Determine if current question has already been answered
Thanks, Tony! This method does return an empty value.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now