Hi,
thanks so much @tpartner!
I tried to get the SID with the given code, but it did not return the SID, since console.log($('input#fieldnames' ).length); . returns 0, i.e. there are no fieldnames on the page where participants can enter their token. Right?
Code:
$( 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?
});
But that brought me to the idea to extract the SID from the URL - unfortunately it's hardcoded, but it works in my case: I get the survey specific token messages I wanted.
Code:
$(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);
}
})
Also thanks a lot for your hint with the "===" exact comparison - it's decisive in this case - thanks a lot!
Is the upper code "OK"? Or is there something I should avoid? (probably hardcoding
Thanks and all the best,
G