Refresh div contents after making changes

Below is my code which is working fine...

<Script type="text/javascript">
function im()
    var Name=document.getElementById("Name").value;
    var pointsize=document.getElementById("pointsize").value;
    var format=document.getElementById("format").value;
    var bckclr=document.getElementById("bckclr").value;
    var color=document.getElementById("color").value;
    var bcolor=document.getElementById("bcolor").value;
    var font=document.getElementById("font").value;

        var url = 'Name='+Name+'&pointsize='+pointsize+

        //-----Sending request to server for getting job name list by ajax-----
            type    : "POST",
            url : "i.php?",
            data    : url,              
            cache   : false,
            success : function(html) {
                var pic='<img src="'+html+'">';

and php code...

echo('Name: <input type="text" id="Name" onchange="im()" value="your name"  name="Name" />');

echo('pointsize: <input type="text" id="pointsize" onchange="im()" value="50" name="pointsize" />');

echo('format: <input type="text" id="format" value=".gif" onchange="im()" name="format" />');

echo('BackGround Color: <input type="text" id="bckclr" value="red" onchange="im()" name="bckclr" />');

echo('FontColor: <input type="text" id="color" value="white" onchange="im()" name="color" />');

echo('Border Color: <input type="text" id="bcolor" value="blue" onchange="im()" name="bcolor" />');

echo('<a href="./lang/ims.php"><img src="'.$image.'" height="82" width="82" /></a>');

echo('Font: <input type="text" id="font" value="'.$image1.'" onchange="im()" name="font" />');

echo ('<div id="Div_Im">');
echo('replace me');
echo ('</div>');

As you can see, I am using AJAX to fetch data from server and displayed within its working fine but I need to refresh div everytime I make changes .

How to refresh div when I make some changes... also I need to add a symbol or loading image, when the data is being from server.....How to do that?


Maybe try this:

<script type="text/javascript">

  $('#theIMform input')
      // Automatically creates a Query String for all fields within the parent form
      formdata = $(this).closest('form').serialize();

        type : "POST" ,
        url : "i.php" ,
        data : formdata ,              
        cache : false ,
        error : function( jqXHR , textStatus , errorThrown ){
          // Something went wrong
        } ,
        success : function( data , textStatus , jqXHR ){
          $( "#div_im" )
            .html( '<img src="'+data+'">' )


<form id="theIMform" name="theIMform">
  Name: <input type="text" id="Name" value="your name"  name="Name" />
  pointsize: <input type="text" id="pointsize" value="50" name="pointsize" />
  format: <input type="text" id="format" value=".gif" name="format" />
  BackGround Color: <input type="text" id="bckclr" value="red" name="bckclr" />
  FontColor: <input type="text" id="color" value="white" name="color" />
  Border Color: <input type="text" id="bcolor" value="blue" name="bcolor" />
  <a href="./lang/ims.php"><img src="<?php echo $image; ?>" height="82" width="82" /></a>
  Font: <input type="text" id="font" value="<?php echo $image1; ?>" name="font" />
<div id="div_im">replace me</div>

When you change a page element it's refreshed automatically.

I think your problem is about this line


because you call show to the img element and not on the div.

try to change it in


furthermore i suggest you use jquery to get values, so you need to change color=document.getElementById("color").value; in a more easy color = $('#color').val();

Need Your Help

maven-jetty-plugin for jetty 7.3 and forward

maven jetty

Where is maven-jetty-plugin for jetty 7 ?

AngularJS: validation in model

javascript angularjs validation

How to validate data inside model in AngularJS?