0

I have small question. How to trigger another function when I click on element with onclick="show_order_info(numbers);" Onclick atributes have random numbers, il try regex...

I need the standard function to be executed when I clicked and then mine function, I don't have access to the original js, I just want to improve functional for me

But problem is Uncaught ReferenceError: show_order_info is not defined

$('.redbutton').on('click', /show_order_info\(\d+\)\;/).innerHTML = "YOU CLICKED ME!";
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="javascript:void(0);" onclick="show_order_info(2588093);" class="redbutton" style=""><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Show Order</a>
<a href="javascript:void(0);" onclick="printPdf(&quot;/ajax_partner_orderinfo?uoid=2588093&amp;print=1&quot;)" class="redbutton"><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Print Order</a>

<a href="javascript:void(0);" onclick="show_order_info(2797617);" class="redbutton" style=""><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Show Order</a>
<a href="javascript:void(0);" onclick="printPdf(&quot;/ajax_partner_orderinfo?uoid=2797617&amp;print=1&quot;)" class="redbutton"><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Print Order</a>

1

1 Answer 1

0

You do not execute on click, you execute the regex as a comma delimited statement

Perhaps you mean

const yourFunction = but => but.textContent = "you clicked me";
const show_order_info = order => console.log(order)
const printPdf = url => console.log(url)

$('.redbutton').each(function() {
//  const click = this.onclick.toString().match(/\{\s+?(.*?)\s+?\}/)[1];
    const click = this.onclick;
    this.onclick=null;
  console.log(click)
  $(this).on("click", function() {
    yourFunction(this)
    click()
  })
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="javascript:void(0);" onclick="show_order_info(2588093);" class="redbutton" style=""><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Show Order</a>
<a href="javascript:void(0);" onclick="printPdf(&quot;/ajax_partner_orderinfo?uoid=2588093&amp;print=1&quot;)" class="redbutton"><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Print Order</a>

<a href="javascript:void(0);" onclick="show_order_info(2797617);" class="redbutton" style=""><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Show Order</a>
<a href="javascript:void(0);" onclick="printPdf(&quot;/ajax_partner_orderinfo?uoid=2797617&amp;print=1&quot;)" class="redbutton"><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Print Order</a>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.