Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to show a user the values he chose in some drop-down menus on the submit event in case of mistake
    primarykey
    data
    text
    <p>I need some help because I modified a jQuery script to obtain some drop-down menus that are linked together, from a form of mine. I have a PHP script with 3 different tables on my MySQL database, to let a user choose his region, then with a Ajax call that I do with the jQuery script, I show him only the provinces that belong to that chosen region, and once he chooses the province, I show him only the towns that belong to this province in a similar way.</p> <p>All is ok up to that, but I'd like to do something more: that's to say, if the user forgets to fill in some obligatory fields, (I control all the fields with PHP) when he clicks on submit, I would manage to show him also these three drop-down menus that maybe he has filled, with the choices he has made, without forcing him to fill in the three selects once again.</p> <p>I got no problem in doing that for all the other fields with PHP, but here I use a Ajax call with a jQuery script and I'd like to do it just inside this jQuery script.</p> <p>Here is my script and I miss the final part, as you can see, on the submit event:</p> <pre><code>$(document).ready(function(){ var scegli = '&lt;option value="0"&gt;Scegli...&lt;/option&gt;'; var attendere = '&lt;option value="0"&gt;Attendere...&lt;/option&gt;'; $("select#province").html(scegli); $("select#province").attr("disabled", "disabled"); $("select#comuni").html(scegli); $("select#comuni").attr("disabled", "disabled"); $("select#regioni").change(function(){ var regione = $("select#regioni option:selected").attr('value'); $("select#province").html(attendere); $("select#province").attr("disabled", "disabled"); $("select#comuni").html(scegli); $("select#comuni").attr("disabled", "disabled"); $.post("select.php", {id_reg:regione}, function(data){ $("select#province").removeAttr("disabled"); $("select#province").html(data); }); }); $("select#province").change(function(){ $("select#comuni").attr("disabled", "disabled"); $("select#comuni").html(attendere); var provincia = $("select#province option:selected").attr('value'); $.post("select.php", {id_pro:provincia}, function(data){ $("select#comuni").removeAttr("disabled"); $("select#comuni").html(data); }); }); $("#form_registrazione").submit(function(){ var reg = $("select#regioni option:selected").attr('value'); var prov = $("select#province option:selected").attr('value'); var com = $("select#comuni option:selected").attr('value'); if ( reg &gt; 0 &amp;&amp; prov &gt; 0 &amp;&amp; com &gt; 0 ) // I miss here the final part }); </code></pre> <p>Here's the link to my page of <a href="http://newbielinux.altervista.org/registrazione.php" rel="nofollow">website</a>: it's only in Italian, but nonetheless you can see the undesired behavior I described above, if you make a mistake filling in an obligatory field of the form and you try to send it out.</p> <p>Thanks for your help. Bye.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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