javascript function not getting called after ajax call

Discussion in 'JavaScript' started by priyanka19, Oct 1, 2011.

  1. #1
    Hi,
    I have written a code in which i have created a table within a span element. I am making a call to a javascript function from a row of the table.
    I have also a provision that the table within the span can be replaced by another table based upon an ajax call. The javascript function is not getting called after the innerHTML of span element has been replaced after the ajax call. I have viewed the pagesource in both the cases and could find no error.
    Can anyone please help me with the problem?

    I am giving the piece of code for ur reference.
    <script type="text/javascript">
    [TABLE]
    [TR]
    [TD="class: webkit-line-content"]function add(){
    alert("In add method")
    }
    </script>

    <body>
    [TABLE]
    [TR]
    [TD]<span>
    <table>
    <tr>
    <td><img src="xyz" onclick="add();"/></td>
    </tr>
    </table>
    </span>[/TD]
    [/TR]
    [TR]
    [/TR]
    [/TABLE]




    </body>[/TD]
    [/TR]
    [TR]
    [TD="class: webkit-line-content"][/TD]
    [/TR]
    [TR]
    [TD="class: webkit-line-content"][/TD]
    [/TR]
    [TR]
    [TD="class: webkit-line-content"][/TD]
    [/TR]
    [TR]
    [TD="class: webkit-line-content"][/TD]
    [/TR]
    [/TABLE]
     
    priyanka19, Oct 1, 2011 IP
  2. SheetalCreation

    SheetalCreation Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #2
    <table>
    <tr>
    <td><img src="xyz" onclick="add();"/></td>
    </tr>
    </table>

    Above is the content, in the span, its calling add function on clicking on image. If with the ajax call you are changing the content of the span then that means above content won't be there. It has been replaced with the other content then who will call the add function.

    what is content which you are replacing with above content?


    Sheetal.
     
    SheetalCreation, Oct 2, 2011 IP
  3. priyanka19

    priyanka19 Peon

    Messages:
    4
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The content in the span is being replaced with a new table with some more rows.
    for instance:
    <table>
    <tr>
    <td> <input type="text" value="123"></td>
    <td><img src="xyz" onclick="add();"/></td>
    </tr>
    <tr>
    <td> <input type="text" value="456"></td>
    <td><img src="xyz" onclick="add();"/></td>
    </tr>
    </table>
     
    priyanka19, Oct 4, 2011 IP
    Raj Kumar likes this.
  4. SheetalCreation

    SheetalCreation Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #4
    I tried code and its working fine for me :


    <html>
    <head>
    <script type="text/javascript">
    function add(){
    alert("In add method")
    }


    </script>
    </head>
    <body>


    <h1>My First Web Page</h1>
    <p id="demo">This is a paragraph.</p>


    <span id="1">
    <table>
    <tr>
    <td><img src="xyz" onclick="add();"/></td>
    </tr>
    </table>
    </span>
    <script type="text/javascript">
    function replacecontent(){
    //alert("hi")
    var element = document.getElementById("1");
    element.innerHTML = <table>
    <tr>
    <td> <input type="text" value="123"/></td>
    <td><img src="xyz" onclick="add();"/></td>
    </tr>
    <tr>
    <td> <input type="text" value="456"/></td>
    <td><img src="xyz" onclick="add();"/></td>
    </tr>
    </table>


    }
    replacecontent();
    </script>
    </body>
    </html>


    I am replacing the content on call of replacecontent function, and after replacing also i am able to call add function on click of image.
    That means there is some problem with the code which you are getting as response of ajax. Can you show your ajax call and its response ?


    Sheetal
     
    SheetalCreation, Oct 6, 2011 IP
  5. priyanka19

    priyanka19 Peon

    Messages:
    4
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes there was problem in my ajax function. I found the error.
    Thank you
     
    priyanka19, Oct 7, 2011 IP