Discovering the method to retrieve the values from 2 dropdown lists that are populated by a JavaScript function

I have a pair of dropdown lists in a JSP file labeled 'speciality' and 'super_speciality'. Clicking on an option in the 'speciality' dropdown list dynamically populates options in the 'super_speciality' dropdown list. The values for these dropdown lists are sourced from a JavaScript file named 'specialities.js'. How can I retrieve the selected values from these two dropdown lists in either a Servlet or JSP?

Here is the content of my specialities.js file:

// specialities.js file

var spl_arr = new Array("Dentist","Gynecologist/obstetrician","Dermatologist/cosmetologist",
"Pediatrician","General Physician","Ayurveda","Cardiologist",
"Orthopedist","Ear-nose-throat (ent)","Homeopath");

var SupSpl_arr = new Array();

SupSpl_arr[0]="";
SupSpl_arr[1]="General Dentists|Oral Pathologists|Periodontists|Orthodontists|Cosmetic Dentists|";
SupSpl_arr[2]="Maternal-fetal medicine|Family planning|Reproductive endocrinology and infertility|Female pelvic medicine and reconstructive surgery|Menopausal and geriatric |";
SupSpl_arr[3]="Cosmecaregiver|Desairologist|Hair colorist|Esthecaregiver|";
SupSpl_arr[4]="Fictional pediatricians‎|Neonatologists‎|Pediatric ophthalmologists‎|Pediatric organizations|Women pediatricians|";
SupSpl_arr[5]="Auto-isopathy|Classical homeopathy|Clinical homeopathy|Homotoxicology|Pluralistic homeopathy|";
SupSpl_arr[6]="Multiple Sclerosis (MS)|Parkinson’s disease (PD)|Ankylosing Spondylities (AS)|Rheumatoid arthritis (RA)|Paralysis|";
SupSpl_arr[7]="Cardiac electrophysiology|Echocardiography|Interventional cardiolog|Nuclear cardiology|Pediatric cardiology|";
SupSpl_arr[8]="Hand and Plastic Surgery|Pediatric Orthopaedics|Back and spine conditions|Trauma|";
SupSpl_arr[9]="OTOLOGY-NEUROTOLOGY (EAR)|RHINOLOGY (NOSE)|LARYNGOLOGY (THROAT)|HEAD/NECK/THYROID|ALLERGY|GENERAL OTOLARYNGOLOGY|PEDIATRIC OTOLARYNGOLOGY (CHILDREN)|";
SupSpl_arr[10]="Allergy and Immunology|Anaesthesiology|Endocrinology|Gastroenterology|";

function populateSuperSpecialities( specialityElementId, superSpecialityElementId ){
    ...
}

function populateSpecialities(specialityElementId, superSpecialityElementId){
    ...
}

To include this JS file in your JSP:



Select Speciality: 
Select Super-Speciality: 

Answer №1

When working with JSP and Servlets, accessing element values can be done through the request object.

To retrieve the value of any element, utilize the getParameter method of the request object. The following code snippet in a servlet or JSP will allow you to access the value:

String value = request.getParameter("super_speciality");

Similarly, you can also obtain the values of other parameters as needed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are the differences between using embedded documents and references in a mongoose design model?

I am currently in the process of developing a discussion forum using Node.js and mongoose. The structure I have in mind involves users being able to participate in multiple forums, with each forum containing multiple comments. Additionally, users should ha ...

Incorporating AngularJS and Bootstrap for seamless pagination experience

My JSON data looks like this: http://localhost:3001/images?page=1 {"images":[{"_id":"542e57a709d2d60000c93953","name":"image1","url":"http://www.syll.com","__v":0},{"_id":"542e58e19d237e5b790f4db2","name":"image154","url":"www.rufyge.com"},{"_id" ...

Transforming a JSON string containing multiple arrays into a JavaScript object

My JSON file is structured as follows: { "items":[ { "username":"abc", "orderID":"1234", "commentHistory":[ { "comment":"Comment Date: 2016/12/09 13:44:23" }, { ...

Android is now asking for location permissions instead of Bluetooth permissions, which may vary depending on the version

I am currently troubleshooting a React Native application that relies heavily on Bluetooth permissions. However, I am encountering an issue with the Android platform where the Bluetooth permissions are appearing as unavailable. I have configured the permi ...

Why does my window scroll change when making a $.ajax call?

Encountering a peculiar bug... Whenever my JS code enters the success function after a jQuery $.ajax call, the scroll position on my window suddenly jumps to the bottom of the page. This is problematic for me as I'm developing a mobile page and want t ...

Notification not appearing in PHP

When working with a specific php file, I am encountering an issue where the alert box I have placed before the header is being ignored and the header is executed directly. Can anyone assist me in resolving this issue? Any help would be greatly appreciate ...

Create a series of vertical lines using jQuery

I'm dealing with a JSON data set that I want to use to generate a grid. In addition to the grid, I also need to display vertical lines above it based on certain values: var arr = []; arr= [ {"Measure":"Air Pollution","Rank":"1","Value":"15.5"}, ...

Dropzone JavaScript returns an 'undefined' error when attempting to add an 'error event'

When using Dropzone, there is a limit of 2 files that can be uploaded at once (maxFiles: 2). If the user attempts to drag and drop a third file into the Dropzone area, an error will be triggered. myDropzone.on("maxfilesexceeded", function(file){ a ...

Is there a JavaScript equivalent to the explode function in PHP with similar functionality

I'm facing an issue while attempting to split my string in JavaScript, here is the code I am using: var str = 'hello.json'; str.slice(0,4); //output hello str.slice(6,9); //output json The problem arises when trying to slice the second str ...

Using AngularJS to bind a dynamically created form built in JavaScript

I am looking to dynamically build a form using JavaScript and utilize it within an AngularJS form controller. In the example provided below, the form is not rendering as HTML, and I aim to bind it to the model variable. http://jsfiddle.net/g6m09eb7/ ...

Incorporating and utilizing the HTML5-captured image as a point of reference

I understand that all I need to do to achieve this is insert <input type="file" id="photo" accept="image/*;capture=camera"> However, my lack of coding skills has caused issues with actually grabbing and using the image selected/taken by the user. ...

Clicking a button in jQuery to load the Pagemethods

<script type="text/javascript"> $(document).ready(function() { $('#loadbtn').click(function() { // can 't load opts = { title: 'ABCD', series: [{ ...

How can I utilize ng-repeat in AngularJS to iterate through an array of objects containing nested arrays within a field?

Here is the structure of an array I am working with: 0: {ID: null, name: "test", city: "Austin", UserColors: [{color: "blue"},{hobby:"beach"} ... ]} }... I am currently attempting to ng-repeat over this initial array in my code. However, when I tr ...

The Angular menu items that have dropdowns attached are not showing up on the screen at all

I have been working on developing a complex Angular menu, and while I have made progress with the overall structure, I am stuck on a particular issue. The menu needs to display different options based on the user's role, such as "admin." However, desp ...

Having some success with AngularJs autocomplete feature

Currently working on a small search application that utilizes Elasticsearch and AngularJS. I have made progress in implementing autocomplete functionality using the AngularJS Bootstrap typeahead feature. However, I am encountering difficulties in displayin ...

The Datalist feature in HTML5 offers an auto-suggest functionality that displays a list of options beginning with the

In my project, I am utilizing HTML5 Datalist for autosuggestion. By default, HTML5 follows the keyword contains approach rather than the starts with approach. For example, if my datalist includes one, two, three and I type "o" in the search box, it displ ...

Dynamic scrolling text for overflowing text display

Here's a scenario I'm facing: Let's say I have three div tags, each 100 pixels wide: <--- DIV WIDTH ---> Text in div 1 Text in div two, it overflows Text in div three <--- DIV WIDTH ---> Currently, I've set the following C ...

I am interested in creating a class that will produce functions as its instances

Looking to create a TypeScript class with instances that act as functions? More specifically, each function in the class should return an HTMLelement. Here's an example of what I'm aiming for: function generateDiv() { const div = document.crea ...

Receiving messages in AngularJS with the help of Strophe.js

My XMPP client in AngularJS, inspired by this stackoverflow link. <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d282e382f1d282e382f7331323e3c31">[email protected]</a> can send messages successfully, but <a hr ...

Customizing Material UI Themes

Is there a way to customize the MuiTheme overrides for a specific named element like this? .MuiStepLabel-label.MuiStepLabel-active { color: rgba(0, 0, 0, 0.87); font-weight: 500; I've attempted modifying various classes such as MuiStepLabelLa ...