JavaScript – Get selected value from dropdown list

A JavaScript example to show you how to get the selected value or text from a dropdown list. A drop box list. <select id="country"> <option value="None">– Select –</option> <option value="ID001">China</option> <option value="ID002" selected>United State</option> <option value="ID003">Malaysia</option> </select> Get option value : var e = document.getElementById("country"); var result = e.options[e.selectedIndex].value; alert(result); //ID002 Get option text : …

Read more

PrimeFaces – Open Window By Dropdown Selection

Technology: Primefaces it’s java based web framework to develop web applications using java. It’s one of the compliance frameworks for JSF, there are many other frameworks like omnifaces, richfaces. Primefaces has rich UI components. In this tutorial primefaces, maven, java8, glasifish servers are used. Use case: If you want to open a new page by …

Read more

Android spinner (drop down list) example

In Android, you can use “android.widget.Spinner” class to render a dropdown box selection list. Note Spinner is a widget similar to a drop-down list for selecting items. In this tutorial, we show you how to do the following tasks : Render a Spinner in XML, and load the selection items via XML file also. Render …

Read more

JSF 2 multiple select dropdown box example

In JSF, <h:selectManyMenu /> tag is used to render a multiple select dropdown box – HTML select element with “multiple” and “size=1” attribute. //JSF… <h:selectManyMenu value="#{user.favCoffee1}"> <f:selectItem itemValue="Cream Latte" itemLabel="Coffee3 – Cream Latte" /> <f:selectItem itemValue="Extreme Mocha" itemLabel="Coffee3 – Extreme Mocha" /> <f:selectItem itemValue="Buena Vista" itemLabel="Coffee3 – Buena Vista" /> </h:selectManyMenu> //HTML output… <select name="j_idt6:j_idt8" …

Read more

JSF 2 dropdown box example

In JSF, <h:selectOneMenu /> tag is used to render a dropdown box – HTML select element with “size=1” attribute. //JSF… <h:selectOneMenu value="#{user.favCoffee1}"> <f:selectItem itemValue="Cream Latte" itemLabel="Coffee3 – Cream Latte" /> <f:selectItem itemValue="Extreme Mocha" itemLabel="Coffee3 – Extreme Mocha" /> <f:selectItem itemValue="Buena Vista" itemLabel="Coffee3 – Buena Vista" /> </h:selectOneMenu> //HTML output… <select name="j_idt6:j_idt8" size="1"> <option value="Cream Latte">Coffee3 …

Read more

Spring MVC dropdown box example

In Spring MVC, form tags – <form:select />, <form:option /> or <form:options />, are used to render HTML dropdown box. See following examples : //SimpleFormController protected Map referenceData(HttpServletRequest request) throws Exception { Map referenceData = new HashMap(); Map<String,String> country = new LinkedHashMap<String,String>(); country.put("US", "United Stated"); country.put("CHINA", "China"); country.put("SG", "Singapore"); country.put("MY", "Malaysia"); referenceData.put("countryList", country); } 1. …

Read more

How to set a dropdown box value in jQuery

A simple select / drop down box, with a id=”country”. <select id="country"> <option value="None">– Select –</option> <option value="China">China</option> <option value="United State">United State</option> <option value="Malaysia">Malaysia</option> </select> 1. To display the selected drop down box value. $(‘#country’).val(); 2. To set a drop down box value to ‘China’. $("#country").val("China"); 3. To set a drop down box value to …

Read more