Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Determine if current question has already been answered

Determine if current question has already been answered 1 Jahr 5 Monate her #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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Determine if current question has already been answered 1 Jahr 5 Monate her #88600

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 3837
  • Dank erhalten: 688
  • Karma: 330
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: Squirrelicious

Re: Determine if current question has already been answered 1 Jahr 5 Monate her #88602

Thanks, Tony! This method does return an empty value.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.219 Sekunden
Donation Image