To display the content as a result of a selection from a combobox, but without using a Submit button, the following code can be used. As can be seen, the action completion is due to the onchange
event.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
IF(ISSET($_POST["judet"])) { $judet=$_POST["judet"];} $sql_n1=" SELECT DISTINCT jd_nume,jd_id FROM t_judete WHERE jd_tr_id=181 ORDER BY jd_nume; "; ?> <form method="POST" action=""> <select name="judet" onchange="this.form.submit()"> <option value=''>-- Selectaţi judeţul --</option><?php $rez_n1=mysqli_query($con, $sql_n1); WHILE ($rd1=mysqli_fetch_assoc($rez_n1) ) { IF($rd1['jd_id']==$judet) { ?> <option value="<?php ECHO $rd1['jd_id'];?>" selected ><?php ECHO $rd1['jd_nume'];?></option><?php } ELSE {?> <option value="<?php ECHO $rd1['jd_id'];?>" ><?php ECHO $rd1['jd_nume'];?></option><?php } } ?> </select> <a href="<?php ECHO pathinfo($_SERVER['PHP_SELF'], PATHINFO_BASENAME); ?>">Restart</a> </form> <?php if(isset($_POST["judet"])) { $sql_f=" SELECT DISTINCT j.jd_nume, o.or_nume, o.or_jd_cod, o.or_id FROM t_judete AS j INNER JOIN t_orase AS o ON j.jd_id=o.or_jd_id WHERE o.or_jd_id=$judet ORDER BY o.or_nume "; $rez_f=mysqli_query($con, $sql_f); ?> <table border=1><tr><th>Nr.</th><th>Judeţul</th><th>Indicativ rutier</th><th>Localitatea</th></tr><?php $nr=0; WHILE ($rd_f=mysqli_fetch_assoc($rez_f)) { $nr++; $jd_nume = $rd_f['jd_nume']; $or_nume = $rd_f['or_nume']; $or_jd_cod = $rd_f['or_jd_cod']; echo "<tr><td>$nr</td><td>$jd_nume</td><td>$or_jd_cod</td><td>$or_nume</td><tr>"; } ?></table><?php } ?> |
Of course, if you still want an action button, then onchange="this.form.submit()" will be deleted from SELECT and a SUBMIT button will be inserted ( <input type="submit" value="Afişează"> ).