0

Sample Code:

<img id="image" onclick="addDetails('1','2','3');" src="sample.png"/>

<script>
function addDetails(data1,data2,data3)
{
    $.ajax(
    {
        .....
        .....,
        success: function()
        {
            document.getElementById("image").onclick=function onclick(event){deleteDetails('data1','data2','data3');};
        }    
    });
}
</script>

In the above sample code i am making an ajax call on click of image and after successchanging the onclick function to deleteDetails. Both the functions addDetails and deleteDetails have same value as their parameter. so in the onclick function am trying to set the deleteDetails with the same parameters as of the called method.

The problem here is when i debugged it the actual function which binded with the onclick function is deleteDetails('data1','data2','data3') insted of deleteDetails('1','2','3') . I tried all the possible string operators to print the value but its not happening.

1
  • You are passing in "strings" - pass in the object references, ie - remove the ''. deleteDetails(data1,data2,data3) Commented Oct 16, 2014 at 19:34

1 Answer 1

1

Your arguments are variables, not "Strings" (only strings are wrapped in quotes)

document.getElementById("image").onclick = deleteDetails(data1, data2, data3);
Sign up to request clarification or add additional context in comments.

2 Comments

hi, I have tried this option. The function is binded as deleteDetails(data1, data2, data3) but the vales of the data1, data2 and data3 are not passed instead its searching in my html(document) for variables data1,data2 and data3
Sorry for the last comment it seems i have added '' to the data separately when i checked . Its working

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.