-3

In our ordering system there is an embedded function I have no access to at all. Conveniently there is a spelling error in it so when a user clicks something a popup appears and has grammar issues in it.

Is there a way for me to replace that text or replace the function with a new function that has all the same code but correct spelling?

This is the function I need to edit.. note confirm says 'You selection' not 'Your selection' I'd prefer to replace the whole thing because I may want to do some other edits but for now I'd like to fix that spelling error.

 function showProof()
{
    var blnSubmit = false;
    var strHid='';
    var strSave='';

  if (aryTemplateChoices.length == 0) 
  {
    blnSubmit = true;
  }
  else
  {
    for (var i=1; i<=aryTemplateChoices.length; i++)
    {
        strSave = aryTemplateChoices[i-1];
        if (strSave=='')strSave='0';
        if (document.getElementById('hidctrl'+ i))strHid = document.getElementById('hidctrl'+ i).value;
        if (strHid=='')strHid='0';

      if ((strSave != '0') && (strHid != strSave))
      {
        blnSubmit = true;
        break;
      }

    }
  }

  if (blnSubmit)
  {
    if (confirm('Your selection has changed, do you want to save?'))
    {
      document.getElementById('subtype').value = 'proof';
      document.getElementById('prevclick').value = '';
      document.getElementById('frm1').submit();
    }
  }

  canAddToCart();
  //<!--WRITE-->
  getQuantityPrice()
  //<!--/WRITE-->
    loadProof();

} 
James C
  • 15
  • 3
  • 2
    Just redefine the function (with the same name and corrected code) at a scope closer to where you want to use it. – Scott Marcus Feb 22 '17 at 21:12
  • Why can't you access the code? – Sekalf Nroc Feb 22 '17 at 21:13
  • Depends on where it is definded and how it is being referenced/called. – Kevin B Feb 22 '17 at 21:25
  • its an online ordering system in .net and the code is in one of the asp files that I can't edit. Its likely already fixed in an update but updating the system would take a lot of time with our custom edits. – James C Feb 22 '17 at 21:33
  • @Radiusmg I have posted the answer below. – Scott Marcus Feb 22 '17 at 21:38
  • yes I'm working on where to place it.. There are specific html files in the system I can access and enter code.. so im looking for the area that will place this after the original. – James C Feb 22 '17 at 21:49

1 Answers1

0

It doesn't really matter where the original function is and how you access it, as long as you just redefine the function (with the same name and corrected code) at a scope closer to where you want to use it.

Here's an example:

function foo(){
  console.log("ORIGINAL foo says hello.");
}

function foo(){
  console.log("NEW foo says hello.");
}

// The second declaration is in the same scope as the first, but it comes after the first
// so it overwrites that declaration and the second one is the one that is used.
foo();
Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
  • Finally got this to work and marked as answer Scott. The main hurdle was finding where I could place it so that it appeared after the original in the code. – James C Feb 23 '17 at 16:39