Note that there are some explanatory texts on larger screens.

plurals
  1. PODisabling an option from a selector so it can't be removed
    primarykey
    data
    text
    <p>another newbish question so please bare with me. I have a selector that looks like this:</p> <pre><code>&lt;select id="patientSelect"&gt; &lt;option disabled selected style='display: none;' id="patient0"&gt; Incoming Patients&lt;/option&gt; &lt;option id="patient1"&gt;&lt;/option&gt; &lt;option id="patient2"&gt;&lt;/option&gt; &lt;/select&gt; </code></pre> <p>Because I kind of wanted a placeholder type text (i.e the first option) for the selector. And with my javascript I wanted it so that if the selected option was patient1 and you clicked a button it would be removed and would go back to showing the disabled 'Incoming Patients' thing. The javascript:</p> <pre><code>$(".ui-btn").click(function(){ remove(); $('#patientSelect :selected').attr('selected', '0'); $('#patientSelect').change(); }); function remove(){ var x = document.getElementById("patientSelect"); x.remove(x.selectedIndex); } </code></pre> <p>Problem is it always removes more than 1 option, so if I got rid of "patient2" and tried to run remove() the list becomes a long blank list. All help is appreciated, please don't be too harsh. :P</p> <p><strong>Edit</strong> Sorry, basically I want the text 'Incoming Patients' (which is the first option of my selector) to never be removed. No matter how many times 'function remove()' tries to run. It can remove the other options fine, just never the first one. This may not even be possible, I'm not sure.. If there's another way to get text onto a selector without options that'd be fine too :-)</p> <p>Maybe something like:</p> <pre><code>function remove(){ if(option != 1){ var x = document.getElementById("patientSelect"); x.remove(x.selectedIndex); } } </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