www.webdeveloper.com
Results 1 to 2 of 2

Thread: JavaScript functions not getting called on a div's innerhtml

Hybrid View

  1. #1
    Join Date
    Dec 2013
    Posts
    1

    JavaScript functions not getting called on a div's innerhtml

    Dear All,

    Presently I am working on ajax and JavaScript and having a problem. Due to which I am unable to progress in my work.

    I am not able to call the JavaScript functions at the innerhtml of a div which I am getting from xhr's response test.

    In index.jsp at line 94 at divId.innerHTML=val; , I am putting the editform16.jsp. But no javascript functions of editform16.jsp are working.

    I am pasting these two files..

    Please help me sir.


    var url="editform16.jsp?conno="+valu;
    var xmlHttp;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...

    var xmlHttp = new XMLHttpRequest();

    }
    else if (window.ActiveXObject)
    { // IE
    try
    {
    // Try to create XMLHttpRequest in later versions of Internet Explorer
    var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
    //Try version supported by older versions of Internet Explorer
    var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    }
    try{
    xmlHttp.onreadystatechange=getInfo;
    xmlHttp.open("POST",url,true);
    xmlHttp.send();
    }catch(e){alert("Unable to connect to server");}

    function getInfo()
    {
    if(xmlHttp.readyState==4 && xmlHttp.status==200)
    {
    var val=xmlHttp.responseText;

    var divId = document.getElementById("pageload");
    divId.style.display = "block";
    divId.innerHTML=val;


    Now no javascript functions of editform16.jsp (which I am getting as response text) are working. Please how to call javascript functions within innerHTML onj Onclick etc etcc


  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    php is taken instead of a jsp

    index.htm
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>123</title>
    <style type="text/css">
    body{text-align:center;margin-top:250px;}
    input[type="button"]{cursor:pointer;margin-bottom:25px;}
    </style>
    <script type="text/javascript">
    function doc(id){return document.getElementById(id);}
    
    window.onload=function(){
    
    var valu='some top secret data',
        btn=doc('btn'),
        output=doc('pageload'),
    	url='serverfile.php',
    	params;
    
    btn.onclick=function(){
    output.innerHTML='Sending th AJAX request, please wait...';
    var xhr = new XMLHttpRequest(),
        params='conno='+valu;
    xhr.open("POST",url,true);
    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhr.send(params);
    xhr.onreadystatechange=function(){
    if(xhr.readyState == 4 && xhr.status == 200){
    //response from the php page
    output.innerHTML=xhr.response || 'no response from the server';
    }
    }
    }
    
    }
    </script>
    </head>
    <body>
    <input id="btn" type="button" value="Send AJAX request" />
    <div id="pageload">this is the output div</div>
    </body>
    </html>

    serverfile.php
    Code:
    <?php
    $output='Nothing recieved';
    if(isset($_POST['conno']) && !empty($_POST['conno'])){
    $output = 'We don\'t know what is <b>conno</b> but it is equal to "<b style="color:Crimson">'.$_POST['conno'].'</b>"';
    }
    echo $output;
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles