php - OnChangeEvent in categories and subcategories -
i new php. getting problem in onchange event in select option ...if change categories whole form getting submitted instead of on change value of categories1.
the problem in onchange event in onchange="myform.submit()"
.
<form name="myform" method="post" action="getsearch.php"> <table style=" border:1px solid silver" cellpadding="10px" cellspacing="0px" align="center"> <tr> <td colspan="3" style="background:#0066ff; color:#ffffff; font-size:20px">search</td> </tr> <tr> <td>name</td> <td><input type="text" name="name" size="40" /></td> </tr> <tr> <td>email</td> <td><input type="text" name="email" size="40" /></td> </tr> <tr> <td>phone</td> <td><input type="text" name="phone" size="40" /></td> </tr> <tr> <td>categories</td> <td><select name="first" onchange="myform.submit()"> <option value="">select category</option> <?php $sql="select *from first_category"; $res=mysql_query($sql); echo $res; if(mysql_num_rows($res)>0) { while($row=mysql_fetch_assoc($res)) { if(isset($_post["first"]) , $_post["first"]==$row["first_id"]) $select ="selected='selected'"; else $select=''; echo '<option value="'.$row["first_id"].'" '.$select.'>'.$row["category_name"].'</option>'; } } ?> </select></td> </tr> <tr> <td>categories1</td> <td><select name="second"> <option value="">select second category</option> <?php if(isset($_post["first"])) { $sql="select *from second_category first_id=".intval($_post["first"]); $res=mysql_query($sql); echo $res; if(mysql_num_rows($res)>0) { while($row=mysql_fetch_assoc($res)) { echo '<option value="'.$row["second_id"].'">'.$row["second_categoryname"].'</option>'; } } } ?> </select></td> </tr> <center><tr > <td valign="middle"><input type="submit" value="search" id="hi" name="hi" /></td> </tr></center> </table>
you seem mix php , javascript. php executed on server-side, can not call changing select or (except via ajax).
so if want have behavior, can either dump datas javascript object , iterate on fill second select dynamically or implement via ajax. this: call php script, returning correct values , fill them via javascript. can find tutorial how solve jquery on here: http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html
Comments
Post a Comment