- Posts: 6
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
$(document).ready(function(){ if (typeof tokenlabel === "undefined"){ tokenlabel ="YOUR TOKEN LABEL : "; } if (typeof tokentext === "undefined"){ tokentext ="YOUR TOKEN TEXT DESCRIPTION"; } if (typeof tokenerror === "undefined"){ tokenerror ="<br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>"; } if ($("#tokenform").length ) { $("#tokenmessage").html(tokentext); $("label[for='token']").text(tokenlabel); } else { $("#tokenmessage").html(tokentext+tokenerror); } })
$(document).ready(function(){ var this_surveyId = '{SID}'; /*gets the SID */ window.alert(this_surveyId); /*returns the string "{SID}" and not the actual SID - I guess, I'm the only surprised here :-)*/ if (this_surveyId === 111111){ if (typeof tokenlabel === "undefined"){ tokenlabel ="1 YOUR TOKEN LABEL : "; } if (typeof tokentext === "undefined"){ tokentext ="1 YOUR TOKEN TEXT DESCRIPTION {SID}"; } if (typeof tokenerror === "undefined"){ tokenerror ="1 <br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>"; } } if (this_surveyId !== 111111){ if (typeof tokenlabel === "undefined"){ tokenlabel ="2 YOUR TOKEN LABEL : "; } if (typeof tokentext === "undefined"){ tokentext ="2 YOUR TOKEN TEXT DESCRIPTION {SID}"; } if (typeof tokenerror === "undefined"){ tokenerror ="2 <br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>"; } } if ($("#tokenform").length ) { $("#tokenmessage").html(tokentext); $("label[for='token']").text(tokenlabel); } else { $("#tokenmessage").html(tokentext+tokenerror); } })
// Find the survey and group IDs if($( 'input#fieldnames' ).length != 0) { var fieldNames = $('input#fieldnames').attr('value'); var tmp = fieldNames.split('X'); var sID = tmp[0]; var gID = tmp[1]; }
if (sID == 111111){
$( document ).ready( function() { // Find the survey and group IDs if($( 'input#fieldnames' ).length != 0) { var fieldNames = $('input#fieldnames').attr('value'); var tmp = fieldNames.split('X'); var sID = tmp[0]; var gID = tmp[1]; } // But: this does not work on this page, because ... console.log($('input#fieldnames' ).length); // ... returns 0, i.e. there are no fieldnames on the page where participants can enter their token. Right? });
$(document).ready(function(){ /* Extract SID from URL */ var pathname = window.location.pathname; /* Get the pathname from the URL */ var pathArray = window.location.pathname.split( '/' ); var sID = pathArray[3]; /* in my case (LSdirectory/index.php/111111/newtest/Y#) the SID sits at position 3 */ console.log(sID); /* returns the SID extracted from the URL */ if (sID == 111111){ if (typeof tokenlabel === "undefined"){ tokenlabel ="1 YOUR TOKEN LABEL : "; } if (typeof tokentext === "undefined"){ tokentext ="1 YOUR TOKEN TEXT DESCRIPTION {SID}"; } if (typeof tokenerror === "undefined"){ tokenerror ="1 <br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>"; } } if (sID != 111111){ document.getElementById("token").style.display="none"; /* hides the tokenform */ if (typeof tokenlabel === "undefined"){ tokenlabel ="2 YOUR TOKEN LABEL : "; } if (typeof tokentext === "undefined"){ tokentext ="2 YOUR TOKEN TEXT DESCRIPTION {SID}"; } if (typeof tokenerror === "undefined"){ tokenerror ="2 <br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>"; } } if ($("#tokenform").length ) { $("#tokenmessage").html(tokentext); $("label[for='token']").text(tokenlabel); } else { $("#tokenmessage").html(tokentext+tokenerror); } })
var sID = $('#limesurvey').attr('action').split('sid=')[1];
</script><form id="tokenform" autocomplete="off" action="/fragen/index.php/111111" method="post">
if (sID != 111111){
else {
$(document).ready(function(){ /* Extract SID from URL */ var pathname = window.location.pathname; /* Get the pathname from the URL */ var pathArrayStep1 = window.location.pathname.split( 'sid/' )[1]; /* Split the pathname in two (at the sid) and get the second (=1) element of the array */ var sID = pathArrayStep1.split( '/' )[0]; /* Split the pathname at the "/" and get the first (=0) element of the array */ console.log(sID); /* returns the SID extracted from the URL */ if (sID == 111111){ if (typeof tokenlabel === "undefined"){ tokenlabel ="1 YOUR TOKEN LABEL : "; } if (typeof tokentext === "undefined"){ tokentext ="1 YOUR TOKEN TEXT DESCRIPTION {SID}"; } if (typeof tokenerror === "undefined"){ tokenerror ="1 <br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>"; } } if (sID != 111111){ document.getElementById("token").style.display="none"; /* hides the tokenform */ if (typeof tokenlabel === "undefined"){ tokenlabel ="2 YOUR TOKEN LABEL : "; } if (typeof tokentext === "undefined"){ tokentext ="2 YOUR TOKEN TEXT DESCRIPTION {SID}"; } if (typeof tokenerror === "undefined"){ tokenerror ="2 <br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>"; } } if ($("#tokenform").length ) { $("#tokenmessage").html(tokentext); $("label[for='token']").text(tokenlabel); } else { $("#tokenmessage").html(tokentext+tokenerror); } })