Search code examples
javarenamebusiness-catalyst

Script to change name stops after Dynamic selection


I need to change text within an un-accessible module in Adobe Business Catalyst so far i have the following working but once an option on the screen is updated the script doesn't run again. How do i make it auto refresh/run?

    $(document).ready(function(){
$.fn.replaceText = function( search, replace, text_only ) {
  return this.each(function(){
    var node = this.firstChild,
      val,
      new_val,
      remove = [];
    if ( node ) {
      do {
        if ( node.nodeType === 3 ) {
          val = node.nodeValue;
          new_val = val.replace( search, replace );
          if ( new_val !== val ) {
            if ( !text_only && /</.test( new_val ) ) {
              $(node).before( new_val );
              remove.push( node );
            } else {
              node.nodeValue = new_val;
            }
          }
        }
      } while ( node = node.nextSibling );
    }
    remove.length && $(remove).remove();
  });
};
$("#shippingStateSpan").replaceText( "Destination State", "Do you have a VAT number?" );
});

Any help will be appreciated. thanks


Solution

  • I'm guessing the text is replaced when an option from the select on the page is changed. Try this:

    $(document).ready(function() {
    $.fn.replaceText = function(search, replace, text_only) {
        return this.each(function() {
            var node = this.firstChild,
                val,
                new_val,
                remove = [];
            if (node) {
                do {
                    if (node.nodeType === 3) {
                        val = node.nodeValue;
                        new_val = val.replace(search, replace);
                        if (new_val !== val) {
                            if (!text_only && /</.test(new_val)) {
                                $(node).before(new_val);
                                remove.push(node);
                            } else {
                                node.nodeValue = new_val;
                            }
                        }
                    }
                } while (node = node.nextSibling);
            }
            remove.length && $(remove).remove();
        });
    };
    var refreshIds = setInterval('$("#shippingStateSpan").replaceText( "Destination State", "Do you have a VAT number?" )', 300);
    });