Note that there are some explanatory texts on larger screens.

plurals
  1. PODropdown (Select menu) problem
    primarykey
    data
    text
    <p>I have MySQL tables looking like that</p> <p>regions table</p> <pre><code>id | region ------------------- 1 | Region1 2 | Region2 </code></pre> <p>...</p> <p>and schools table</p> <pre><code>region_id | school ------------------- 1 | schno1 1 | schno5 1 | schno6 2 | scho120 </code></pre> <p>My page works like that: At first, page populates #regions select menu from db table named "regions". when user selects #region, the js sends selected region's value to search.php. Serverside php script searches db table named "schools" for #region (previously selected menu) value, finds all matches and echoes them. </p> <p>Now the question is, how can I hide #class and #school select menus, and show only error message "there is no school found in this region" <strong>if no matches found?</strong> how to check if there's no result from search.php? I'm newbie to js. Please edit my code if it's possible. Thx in advance. Sorry for my bad english</p> <p>My javascript looks like that <a href="http://pastie.org/2444922" rel="nofollow">http://pastie.org/2444922</a> and the piece of code from form <a href="http://pastie.org/2444929" rel="nofollow">http://pastie.org/2444929</a> and finally search.php <a href="http://pastie.org/2444933" rel="nofollow">http://pastie.org/2444933</a></p> <p><strong>UPDATE</strong> I changed my js but no success!</p> <pre><code>$(document).ready(function(){ $("#school").hide(); $("#class").hide(); searchSchool = function(regionSelect){ var selectedRegion = $("select[name*='"+regionSelect.name+"'] option:selected").val(); if (selectedRegion!='0'){ $.ajax({ type: "POST", url : "core/code/includes/search.php", data: "&amp;region_id="+selectedRegion, success: function(result, status, xResponse){ if (result!=null){ $("#school").show(); $("#class").show(); $("#school").html(result); }else{ $("#error").html("There is no school found in this region"); $("#school").html(''); $("#school").hide(); } }, error: function(e){ alert(e); } }); }else{ $("#error").html('Please select a region first'); $("#school").html(''); $("#school").hide(); $("#class").hide(); } } }); </code></pre>
    singulars
    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.
 

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