narjis Posted December 13, 2011 Share Posted December 13, 2011 I am posting two valuies via text box and textarea but these values are not being posted to my php script please chechk my code where I'm going wrong. In my database blanck values are being inserted. // JavaScript Document $(document).ready(function(){ $("#response").hide(); $("input.addbtn").click(function(){ var name = $("#name").val(); var comment = $("#comment").val(); //var datastring ="name="+name+"&comment="+comment; $.post( 'process.php', ( name, comment ), function(response){ $("#response").fadeIn("fast"); $("#response").html("Comment Added").css("padding","10px"); $("#name").val(""); $("#comment").val(""); $("#wrapper").hide(); } ) return false; }); }); Here is my html code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Page1</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript" src="script.js"></script> </head> <body> <div id="wrapper"> <table align="center"> <form method="post" action="" class="commentForm"> <tr> <td colspan="2"><th colspan="2">Add your Comments</th> </td> </tr> <tr> <td colspan="2"><label for="name" >Name :</label></td><td width="161"><input type="text" name="name" id="name" /></td> </tr> <tr> <td colspan="2"><label for="comment" >Comment :</label></td> <td><textarea name="comment"cols="20" rows="5" id="comment"></textarea> </td> </tr> <tr> <td> <input align="center" class="addbtn" type="submit" name="submit" value="Add" /></td> </tr> </form> </table> </div> <div id="response"></div> </body> </html> Quote Link to comment Share on other sites More sharing options...
gristoi Posted December 13, 2011 Share Posted December 13, 2011 try changing this part: $.post( 'process.php', ( name, comment ), to: $.post( 'process.php', { name : name, comment : comment }, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.