473,378 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Trying to capture the value of Select options List

I am one of those old school dinosaur types that has been around since the great depression and to be perfectly honest with you I am very comfortable with JavaScript and do not revert to plug-ins such as jQuery when I can get the same job done with pure clean JavaScript, but when I am trying to capture values from select options lists I used to use
var varName= document.formName.selectName.options[selectName.selectedIndex].value
I LIKE THIS OLD FASHION WAY BECAUSE IT IS CLEAN AND EASY TO UNDERSTAND and even though I do use jQuery when I have no better choices the truth I find is that the additional lines of code that jQuery saves me isn't enough to be significant, and I am not a lazy coder...
But I am finding that doesn't work any more and now I am finding it more and more difficult to do the kind of coding I am used to, so any help would be very much appreciated???
I have to be leaving something out, I am sure the problem is with syntax but I haven't found it yet, and the same code seems to work on older web pages just fine.
By the way I am using windows 10/64
Nov 4 '17 #1
2 2568
Simply use
Expand|Select|Wrap|Line Numbers
  1. alert($("#selectListId").val())
. It will show the selected value in the alert box.
Feb 1 '18 #2
gits
5,390 Expert Mod 4TB
well - the OP didn't want to use jQuery for such a simple operation - but even noone answered the OPs question until now. So a simple example to achieve it with vanilla javascript can be found here:

https://www.w3schools.com/jsref/tryi..._select_value2

so if the only thing that would have to be done would be to retrieve the value of a select-element then including jQuery for this line that basically does the 'magic':

Expand|Select|Wrap|Line Numbers
  1. var x = document.getElementById("mySelect").value;

would create the overhead of loading that lib for that only. Besides that - the (jQuery-) $-function obviously wraps exactly the plain DOM-methods - but this way it can only be slower - since basically you call a facade that dispatches to the correct DOM-method in the end. This is of course a theoretical issue - but when it comes to a point where you would use such facade-methods in a loop it can be significantly slower.
Feb 1 '18 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: tomhath | last post by:
Can someone give an opinion whether this is a dumb approach? I want to generate a list of OPTION elements for s SELECT element, but I can't see any (clean) way to use a template on a list of...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
4
by: VK | last post by:
I'm looking for autoexpand <select> list onfocus and collapse it back onselect/onblur (the list is select-one type) I know it is not possible directly, but I've seen here a hack by changing...
2
by: onetitfemme | last post by:
How come this works http://www.geocities.com/tekmonk2005/testSelectJS00.html works fine in Konqueror, but this http://www.geocities.com/tekmonk2005/testSelectJS02.html doesn't in FireFox,...
3
by: tim | last post by:
hi there, i am trying to build an option list using the following code "<td><select name="select"> <option value="<Computed Value>"><Computed Value></option> </select></td>" the "Computed...
1
by: Leonardo Calado | last post by:
Hi, I have the following problem: I have 4 select fields like; <select id="choice_101" name="choice_101"> <option label="Will not attend" value="Will not attend" selected="selected">Will not...
3
by: Beholder | last post by:
I hope that someone can help me with the following: Short background explenation: I have a shrfepoint page (newform.aspx) in a item list. On this page is a lookup column that displays a lookup...
5
by: =?Utf-8?B?bWNhdWxpZmZl?= | last post by:
I have an old application ( pre-VB5) that I need to add a select/option list to. This is an edit program so the values for the form will be retrieved from a database. How do I set the value of...
1
by: madflytom | last post by:
Hello again all. I posted a question last night about dealing with <optgroups> in select boxes. We've changed directions, and now I need a little more help. Here's the scenario: Two select...
1
by: Casiviani | last post by:
I'm working with some dynamic pages and I want to implement an event that fires when I rollover the options in a Select control, I mean before of select the value, this is for displaying a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.