javascript - Ajax text field to divtag1 and other text field to divtag2 using php -


<html> <head> <meta charset="utf-8" /> <title>jquery ajax - post</title> <script type="text/javascript" src="jquery_1.6.1.js"></script> <script type="text/javascript"><!-- $(document).ready(function() {   $('form').submit(function() {     var data = 'name='+$('#nm').val();     var data = 'name='+$('#sn').val();     $.post('script.php', data, function(response){       $('#dv').html(response);       $('#dv2').html(response);     });      return false;      // required not open page when form submited   }); }); --></script> </head> <body> <div id="dv">here displayed response.</div><br /> <form action="script.php" method="post">  name: <input type="text" name="nm" id="nm" /><br /> <div id="dv2">here displayed 2nd response.</div><br />  second name: <input type="text" name="sn" id="sn" /><br />  <input type="submit" value="submit" /> </form> </body> </html> 

i want name post javascript , come out under divtag (dv) , second name come out (dv2) - looked around ever seem find how echo variable out in 1 div tag.

check out. declared same name data passed script.php . here edited code.it working.

<html> <head> <meta charset="utf-8" /> <title>jquery ajax - post</title> <script type="text/javascript" src="jquery_1.6.1.js"></script> <script type="text/javascript"><!-- $(document).ready(function() {   $('form').submit(function() {     var nm = $('#nm').val(); // changes made     var sn= $('#sn').val();     $.post('script.php',{     name1:nm,     name2:sn   }, function(response){       var resp=response.split("."); // spiltting different output       $('#dv').html(resp[0]);       $('#dv2').html(resp[1]);     });      return false;      // required not open page when form submited   }); }); --></script> </head> <body> <div id="dv">here displayed response.</div><br /> <form method="post"> // no need specify script.php here  name: <input type="text" name="nm" id="nm" /><br /> <div id="dv2">here displayed 2nd response.</div><br />  second name: <input type="text" name="sn" id="sn" /><br />  <input type="submit" value="submit" /> </form> </body> </html> 

get parameter in script.php follows

<?php   string name1 =$_post["name1"]; string name2= $_post["name2"]; // calculations  string together= name1 +"."+ name2; // make different output 1 string out.print(together); ?> 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -