Note that there are some explanatory texts on larger screens.

plurals
  1. POhow manage auto-submit with the action atribute in the form
    text
    copied!<p>I needed make a dinamic dependent dropdown in a form,so i found this solution that uses the JS auto-submit function:</p> <pre><code>function autoSubmit() { var formObject = document.forms['dados']; formObject.submit(); } </code></pre> <p>then I use the onchange event in the first dropdown to call the auto-submit function:</p> <pre><code>&lt;label&gt;Campus:&lt;/label&gt; &lt;select name="campus" onchange="autoSubmit();"&gt; &lt;option VALUE="null"&gt;&lt;/option&gt; &lt;?php //Popula a lista com os cursos do DB $sql = "SELECT id,nome FROM campus"; $countries = mysql_query($sql,$conn); while($row = mysql_fetch_array($countries)) { if($row[nome]==$campus) echo ("&lt;option VALUE=\"$row[nome]\" selected&gt;$row[nome]&lt;/option&gt;"); else echo ("&lt;option VALUE=\"$row[nome]\"&gt;$row[nome]&lt;/option&gt;"); } ?&gt; &lt;/select&gt; </code></pre> <p>with this the element "campus" will be setted to be used in the second dropdown SELECT statement:</p> <pre><code>$campus = $_POST['campus']; ... &lt;label&gt;Curso: &lt;span class="small"&gt;curso corrente&lt;/span&gt; &lt;/label&gt; &lt;select name="curso"&gt; &lt;option VALUE="null"&gt;&lt;/option&gt; &lt;?php $consulta2 = "SELECT curso FROM campus_cursos WHERE campus = \"" . $campus . "\""; $cursoslista = mysql_query($consulta2,$conn); while($row = mysql_fetch_array($cursoslista)) { echo ("&lt;option VALUE=\"$row[curso]\"&gt;$row[curso]&lt;/option&gt;"); } ?&gt; &lt;/select&gt; </code></pre> <p>this code is working,but the problem is that in this way I cant set a action atribute in the form because if i do this every time the first dropdown changes it will redirect to the action's URL.this is the form that works:</p> <pre><code>&lt;form name="dados" method="POST" onsubmit="return validar();"&gt; </code></pre> <p>with no action atribute I cant use a submit button to send the data of all the others elements to the right URL.there is a way to this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload