Block onClick function
Clash Royale CLAN TAG#URR8PPP
Block onClick function
I am trying to block a particular onClick function on my site. I have written the following but it doesn't appear to block the function. Any ideas?
It works if I remove ('xx=d&') but I only want it to block the function when this is present.
JS
function AJFK_AjaxUpdateForm('xx=d&') (event)
event.preventDefault();
This part
function AJFK_AjaxUpdateForm('xx=d&') (event)
does not make sense, is supposed to be just function AJFK_AjaxUpdateForm(event)
if you want to pass more than 1 argument function AJFK_AjaxUpdateForm(arg1, event)
etc... But the question is where does 'xx=d&' come from? is it an id? class? a specific property of the element?– Bargros
Aug 10 at 11:22
function AJFK_AjaxUpdateForm('xx=d&') (event)
function AJFK_AjaxUpdateForm(event)
function AJFK_AjaxUpdateForm(arg1, event)
1 Answer
1
Your problem is your constructor..
function AJFK_AjaxUpdateForm('xx=d&') (event){
function AJFK_AjaxUpdateForm('xx=d&') (event){
You have a hard string in there, where you should be having your parameter name.. and you've got two.. brackets which in your case is invalid... unless the function returns a function declaration which I assume your example doesn't.
Your constructor should look like the below:
function AJFK_AjaxUpdateForm(event){
function AJFK_AjaxUpdateForm(event){
If you open Developer Tools > Console, you'll start seeing your JavaScript errors as pointed out in the comments section.
As per your question in the comments; you would do a simple string comparison:
var block = 'xx=d&';
function AJFK_AjaxUpdateForm(event)
if(block == 'xx=d&')
event.preventDefault();
if you want to pass the 'block' variable as part of the constructor you need to add another variable:
function AJFK_AjaxUpdateForm(event, block){
function AJFK_AjaxUpdateForm(event, block){
And if you're using inline handler to execute the function; you must update it rather than hard-coding the string:
<a href="/Home" onclick="AJFK_AjaxUpdateForm(event, 'xx=d&')">Test the Method</a>
<a href="/Home" onclick="AJFK_AjaxUpdateForm(event, 'xx=d&')">Test the Method</a>
Going back to the dual brackets, if you want to know.. is actually a valid syntax as I mentioned above if your function returns a function declaration.
In this example, it's perfectly valid to use the double brackets.
var f = function()
return function()
console.log("123");
f()();
But that might be outside the scope of what you're trying to do, and it's just something to learn ;)
Hi Adrian Thank you for your help. I can block AJFK_AjaxUpdateForm but I only to block it with the following parameters AJFK_AjaxUpdateForm('xx=d&') . Are you able to advise a way I can do this? E.G. Blocks AJFK_AjaxUpdateForm('xx=d&') but doesn't block AJFK_AjaxUpdateForm('1234'). is this possible?
– James Harding
Aug 10 at 11:17
Where are you getting 'xx=d&' from? You can't hardcode a string into a constructor, I have added an edit hopefully addressing your issue.
– Adriani6
Aug 10 at 11:25
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You are probably getting a syntax error on your console. Check it out.
– DontVoteMeDown
Aug 10 at 11:01