php - jquery to load a new page and post data from an on change event -
i building website identify parts based on 10 different measurements. wanting my onchange event first drop down box 2 things. first, need post selection php variable on next page. second, want function load next page give me drop down list shows options have same measurement first list. building 10 pages keep adding on sql statement generates drop down list. not sure how send jquery post php variable, , how load new page. new programming, trying keep not complicated. here basics of code.
<html> <head> <script type = "text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script type='text/javascript'> function get() { var lengthdata = $('#filter').serialize(); $.post('spline.php', lengthdata, function(output){ $('#list').html(output); }); } </script> </head> <body> <div id="id1"></div> <?php //database login , connection. $dbhost = "localhost"; $dbuser = "root"; $dbpass = "password"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("could not connect!"); $select_db = mysql_select_db('camdb') or die('could not select camdb database!!'); echo "<style type='text/css'>"; echo "td {padding: 10px;}"; echo "</style>"; echo "<form name='filter' id='filter'><table><tr>"; echo"<div id='lengthsel'>"; $query = "select distinct length camtable;"; $result = mysql_query($query); echo"<td>cam length" . "<br/>"; echo"<select name=\"length\" id='length' onchange='get()'>/n"; echo"<option value=''>select</option>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['length'] . "'>" . $row['length'] . "</option>"; } echo "</select></td>"; echo"</tr></table></form>"; echo"</div>"; ?> <div id="list"></div> </body> </html>
this rest of pages are
<html> <head> <script type = "text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script type='text/javascript'> function get() { var splinedata = $('#filter').serialize(); $.post('spider.php', splinedata, function(output){ $('#list').html(output); }); } </script> </head> <body> <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = "password"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("could not connect!"); $select_db = mysql_select_db('camdb') or die('could not select camdb database!!'); $sql = "select * camtable "; if ($_request['length'] != "") { $sql.='length="' . mysql_real_escape_string($_request['length']) . '";'; } //$sql.="order length, spline, spider, support, head, nose, grov1"; echo $sql . "<br/>"; $result = mysql_query($sql); $sql = "select * camtable "; if ($_request['length'] != "") { $sql.='length="' . mysql_real_escape_string($_request['length']) . '";'; } $result = mysql_query($sql); echo"<td>spline" . "<br/>"; echo"<select name=\"spline\"id='spline' onchange='get()'>/n"; echo"<option value=''>select</option>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . row['spline'] . "'>" . $row['spline'] . "</option>"; } echo "</select></td>"; ?> </body> </html>
i think looking
$(document).ready(function(){ $('select').change(function(){ $('#form1')[0].submit();}); });
assuming select inside form <form id="form1" action="secondpage.php" method="post">
and in second page catch value using $_post['selectname']
Comments
Post a Comment