- Posts: 42
- Thank you received: 4
Ask the community, share ideas, and connect with other LimeSurvey users!
$("span input.checkbox").each(function(){ if ( some_test_to_see_if_the_current_input_is_an_exclusive_item ) { $(this).attr('isExclusive',true); } ; });
/* The following marks all li elements and all of its child elements with the property: isexclusive="true" whenever the script for handling exclusives is produced on the page, i.e. var LEMalias2varName = { 'medproc_01':'java558215X26X38901', '558215X26X38901':'java558215X26X38901', 'medproc_999':'java558215X26X389999', '558215X26X389999':'java558215X26X389999'}; In the case I am working on two options are exlusive, option 1 and option 999. Basically the only way I could figure out to grab that variable was to parse the html() for the page looking for the variable "LEMalias2varName" and grab the information about the exclusive codes from there. This code is in need of refactoring, but seems to be doing the job. I present my questions one-by-one, so if you present your surveys in a different manner, you would need to be more careful to assure that the question you are working with is the correct one from the group. Since I only ever have one question per screen, not an issue for me. */ function markExclusive(){ var muchtext, start, startsearch, end, endsearch, exclArray, lineArray, itemArray, exclItemList, exclString ; exclArray = []; exclString = ""; muchtext = $('form').html(); startsearch = 'var LEMalias2varName = {' ; endsearch = "}"; start = muchtext.lastIndexOf(startsearch) + startsearch.length ; end = muchtext.indexOf(endsearch,start); exclItemList = muchtext.substring(start,end); // grab the important text lineArray = exclItemList.split(','); // split at the commas which ends up being into lines for ( i = 0; i < lineArray.length; i++) { // traverse each line itemArray = lineArray[i].split(':'); // split again at the colons for ( j = 0; j < itemArray.length; j++) { // traverse each item/word // check for the 'java' text which should only occur once per variable if ( itemArray[j].indexOf('java')>-1 ) { // switch out 'java' for 'javatbd' which is the prefix of the 'li' element var arrayItem = itemArray[j].replace('java','#javatbd'); if ( exclArray.indexOf(arrayItem)===-1 ) { // place in array of exclusive items exclArray.push(arrayItem); } } } } exclString = exclArray.toString(); // turn the array into a string, extra step meh! $("td.answer ul li").each(function(){ // check each li for presence in the array, awkward currid = $(this).attr('id'); if ( exclString.indexOf(currid) > -1 ) { // if found set new exclusive property $(this).attr('isExclusive',true); $(this).find("*").attr('isExclusive',true); } }); }