Reputation: 3751
XSL:
<script type="text/javascript">
<xsl:value-of select="concat('replaceAll(',$idS,');')"/>
</script>
HTML:
<script type="text/javascript">replaceAll(ID0ED);</script>
Javascript:
$(function () {
var cityNameRye = $("#spnCityID0ED").text().split(";")[1];
if (cityNameRye.toLowerCase() == "rye") {
//do something
}
});
I get the following error in the console which causes an issue in the site:
Uncaught ReferenceError: replaceAll is not defined
Can I create a dummy function which clears out the error?
Upvotes: 0
Views: 283
Reputation: 1599
Put this function code somewhere when it could be loaded before those from XSL are executed:
function replaceSpnCity(idPart) {
var idsToReplace = $("[id^='spnCity']"); //updated missing quote
idsToReplace.each(function() {
var id = $(this).attr('id');
var newId = id.replace(idPart,'');
$(this).attr('id',newId);
});
}
And call it from XSL like:
<xsl:value-of select="concat('replaceSpnCity('',$idS,'');')"/>
Upvotes: 1
Reputation: 282
You do not have any function with the name replaceAll() in your code
try
function replaceAll(varName){
//code to execute
}
and see if you still have the error
Upvotes: 1