PDA

View Full Version : Hiding an option from a select list



ktbadham
Aug 6th, 2012, 02:46 PM
I am using a CMS for my website, and want to implement some javascript to do some things for me that don't have options in the software. An example of this is hiding options in a drop down menu. I am not very good at javascript, and I have not been able to find anything through googling that actually works.

An example is I have a drop down for address where you can select new address, logged in user or unknown, and I want to hide unknown. Here is the code from the page:

<select class="BBFormSelectList EventItemRegistrantSelectList" id="PC7102_Wizard1_dgEventItems3_dgRegistrationsList_0_dgRegistrantList_0_ddlAddress_0" onchange="javascript:setTimeout('__doPostBack(\'PC7102$Wizard1$dgEventItems3$ctl02$dgRegistrationsList$ctl02$d gRegistrantList$ctl02$ddlAddress\',\'\')', 0)" name="PC7102$Wizard1$dgEventItems3$ctl02$dgRegistrationsList$ctl02$dgRegistrantList$ctl02$ddlAddress">
<option value="-1">&lt;Please Select&gt;</option>
<option value="0">New address</option>
<option value="1">Supervisor FULL RIGHTS's address</option>
<option value="2" selected="selected">Unknown</option>
</select>

How do I hide just <option value="2" selected="selected">Unknown</option>? or if it's not possible to hide unknown for some reason, is it possible to hide either of the other selections?

Philip M
Aug 6th, 2012, 03:45 PM
To remove an option from a select list, set the value to null. That removes the option from the list, with any options below it moving up to occupy the void.



<script type = "text/javascript">

var theid = "PC7102_Wizard1_dgEventItems3_dgRegistrationsList_0_dgRegistrantList_0_ddlAddress_0";
var obj = document.getElementById(theid);
obj.options[3] = null;
obj.selectedIndex = 0;

</script>

“Expert: a man who makes three correct guesses consecutively.”
Dr. Laurence J. Peter (American "hierarchiologist", Educator and Writer, 1919-1990)

ktbadham
Aug 6th, 2012, 04:16 PM
Thank you so much!

For the record it didn't work, but it did lead me down another path that makes me think something else the software is using is interfering with the script, so this was helpful none the less.

Philip M
Aug 6th, 2012, 07:34 PM
Thank you so much!

For the record it didn't work, but it did lead me down another path that makes me think something else the software is using is interfering with the script, so this was helpful none the less.

It works for me! :)