Unable to display background image using javascript on qualtrics -
for starters, have absolute no knowledge javascript. trying display background image extracted url address on page of questionnaire on qualtrics following codes:-
qualtrics.surveyengine.addonload(function() { <div id="divtest">hello</div> <img id="imgtest" /> <img id="imgreal" src="http://webneel.com/wallpaper/sites/default/files/images/01-2014/2-flower-wallpaper.jpg" /> var string = 'http://webneel.com/wallpaper/sites/default/files/images/01-2014/2-flower-wallpaper.jpg'; document.getelementbyid("divtest").style.backgroundimage = "url('" + string + "')"; document.getelementbyid("imgtest").src = string; });
but got following error message:-
invalid javascript! cannot save until fix errors: unexpected token <
how go fixing this?
you cannot add html directly in javascript code, have create body section of page, or if need create elements via code have use createelement
var _div = document.createelement('div'); _div.id = 'divtest'; _div.innerhtml = 'hello'; _div.style.backgroundimage = "url('" + string + "')"; document.getelementsbytagname('body')[0].appendchild(_div); // place child of body
or
document.getelementbyid('[id of parent element]').appendchild(_div); // place child of other element.
Comments
Post a Comment