Forloop and Javascript submit in PHP -
i have code this.
as per previous question, dont want send values in url , going hidden field.
in below code, when submit form, able post values in next page first row value (first while loop record).
why? when inspect firebug able see hidden values records.
in other words, first record getting posted next page , not consecutive records.
if below code looks crazy, me in such way don't want pass values in url or anywhere in browser/webform
<!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=iso-8859-1" /> <title>books</title> <script type="text/javascript"> function test() { document.forms.testform.submit(); } </script> </head> <body> <?php mysql_connect("localhost","root","password"); mysql_select_db("books"); $result = mysql_query("select b_code,author_name books"); while($row = mysql_fetch_array( $result )) { ?> <form action ="post.php" id="testform" method="post"> <input type="hidden" name="name" value="<?php echo $row['b_code']; ?>" /> <input type="hidden" name="id" value="<?php echo $row['author_name']; ?>" /> </form> <a href="#" onclick="test()"><?php echo $row['author_name']; ?></a> <?php } ?> </body> </html>
thanks, kimz
try solution...
<!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=iso-8859-1" /> <title>books</title> <script type="text/javascript"> function test(name,id) { document.getelementbyid("name").value = name; document.getelementbyid("id").value = id; document.forms.testform.submit(); } </script> </head> <body> <form action ="post.php" id="testform" method="post"> <?php mysql_connect("localhost","root","password"); mysql_select_db("books"); $result = mysql_query("select b_code,author_name books"); while($row = mysql_fetch_array( $result )) { ?> <a href="#" onclick="test('<?php echo $row['b_code']; ?','<?php echo $row['author_name']; ?>')"><?php echo $row['author_name']; ?></a> <?php } ?> <input type="hidden" name="name" value="" id="name"/> <input type="hidden" name="id" value="" id="id"/> </form> </body> </html>
Comments
Post a Comment