0

I was trying the next code without success

HTML

<a id="addBookButton" href="javascript:showForm('addBookButton','add-book','activateAddBookForm');" class="addA"><span>Add Book</span></a>

Javascript


function showForm(button,form,callback) {
    $("#"+button).hide();
        $("#"+form).show();
        callback();
}

5 Answers 5

5

You can just pass a reference to the function into your showForm function.

<a id="addBookButton" href="javascript:showForm('addBookButton','add-book',activateAddBookForm);" class="addA"><span>Add Book</span></a>
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

function showForm(button,form,callback) {
    $("#"+button).hide();
    $("#"+form).show();
    if (typeof this[callback] == "function") this[callback]();
}

Of you pass the function by value and not just the name of it:

<a id="addBookButton" href="javascript:showForm('addBookButton','add-book',activateAddBookForm);" class="addA"><span>Add Book</span></a>

Comments

0

Change your a tag to:

<a id="addBookButton" href="#" onclick="showForm('addBookButton','add-book','activateAddBookForm'); return false;" class="addA"><span>Add Book</span></a>

Note the onclick handler, and the return false; within the onclick.

Comments

0
function showForm(button,form,callbackName) {
    $("#"+button).hide();
    $("#"+form).show();
    var callback = window.callbackName;
    if(typeof callback === 'function') {
        callback();
    }
}

Comments

0
<a id="addBookButton" onclick="javascript:showForm('addBookButton','add-book','activateAddBookForm');" class="addA"><span>Add Book</span></a>

Javascript

function showForm(button,form,callback) {
  // Your Code
}

function callFunction(){
  document.getElementById('addBookButton').onclick();
}

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.