Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to empty select box when "Please Select" option is chosen
    primarykey
    data
    text
    <p>I have a drop down menu and an empty select box below:</p> <pre><code>&lt;select name="session" id="sessionsDrop"&gt; &lt;option value=""&gt;Please Select&lt;/option&gt; &lt;option value='20'&gt;EWYGC - 10-01-2013 - 09:00&lt;/option&gt; &lt;option value='22'&gt;WDFRK - 11-01-2013 - 10:05&lt;/option&gt; &lt;/select&gt; &lt;/p&gt; $studentSELECT = ""; $studentSELECT .= '&lt;select name="studenttextarea" id="studentselect" size="6"&gt;'; $studentSELECT .= '&lt;/select&gt;'; </code></pre> <p>The above is in the <code>addstudent.php</code> page:</p> <p>Now what happens is that I have a php code where depending on which assessment is chosen from drop down menu, it runs a query and it displays either a list of students in the select box if rows from the db are found, if no rows are found then it simply displays a message stating that no students were found within an assessment in the select box. The code for this is below which is in the <code>addedstudents.php</code> page and is accessed through ajax.</p> <pre><code>$studentnum = $currentstudentstmt-&gt;num_rows(); $studentSELECT = ""; if($studentnum == 0){ $studentSELECT .= "&lt;option disabled='disabled' class='red' value=''&gt;No Students currently in this Assessment&lt;/option&gt;"; } else { while ( $currentstudentstmt-&gt;fetch() ) { $studentSELECT .= sprintf("&lt;option disabled='disabled' value='%s'&gt;%s - %s %s&lt;/option&gt;", $dbStudentId, $dbStudentAlias, $dbStudentForename, $dbStudentSurname) . PHP_EOL; } } echo $studentSELECT; </code></pre> <p>The problem I have is that if the user selects the <code>Please Select</code> option, it still displays the message stating no assessments are found, this is because obviously there are no modules in this query so it thinks that as it has no rows display the message. But I don't want this to be dislayed if the <code>Please Select</code> option is selected, I just want the select box to just be empty. </p> <p>Problem is that even though I tried to use jquery to do this, what happens is the select box goes empty but then comes back with the message milliseconds later.</p> <p>My question is that if the <code>Please Select</code> option is chosen from drop down menu, what is best way to be able to display an empty select box?</p> <p>Below is attempt of this through jquery:</p> <pre><code>$('#sessionsDrop').change( function(){ if( $(this).val() == '' ){ $('#studentselect').val(''); } }); </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