If you have a select element that looks like this:
<select id="ddlViewBy"> <option value="1">test1</option> <option value="2" selected="selected">test2</option> <option value="3">test3</option> </select>
Running this code:
var e = document.getElementById("ddlViewBy"); var strUser = e.value;
Would make strUser
be 2
. If what you actually want is test2
, then do this:
var e = document.getElementById("ddlViewBy"); var strUser = e.options[e.selectedIndex].text;
Which would make strUser
be test2
Related Posts:
- Scroll to the top of the page using JavaScript?
- Generate pdf from HTML in div using Javascript
- How to terminate the script in JavaScript?
- How do I change an HTML selected option using JavaScript?
- Clearing localStorage in javascript?
- How to ‘minify’ Javascript code
- ++someVariable vs. someVariable++ in JavaScript
- How to check whether a Button is clicked by using JavaScript
- Get a random item from a JavaScript array
- JavaScript: IIF like statement
- Adding options to a
- Getting DOM element value using pure JavaScript
- jQuery remove options from select
- How do I select text nodes with jQuery?
- How do you remove all the options of a select box and then add one option and select it with jQuery?
- Empty functions in Javascript
- Change the selected value of a drop-down list with jQuery
- Using prevNext Modx Addon
- How to convert decimal to hexadecimal in JavaScript
- What does “javascript:void(0)” mean?
- How to set time delay in javascript
- How can I remove a specific item from an array?
- Difference between associative entity and associative relationship attribute?
- max value of integer
- How to install apoc for neo4j?
- require is not defined? Node.js
- PHP – exit or return which is better?
- Loop inside React JSX
- How do you copy and paste into Git Bash
- How to make JavaScript execute after page load?
- Encode URL in JavaScript?
- How can I refresh a page with jQuery?
- What does “?” mean in Java?
- How to override equals method in Java
- Module not found can’t resolve
- How can I get file extensions with JavaScript?
- How to detect Safari, Chrome, IE, Firefox and Opera browser?
- What does on() in JavaScript do?
- Palindrome check in Javascript
- Console is throwing Unterminated JSX contents error
- Console.log not working at all
- includes() not working in all browsers
- Has the nativescript sidekick discontinue?
- Print the contents of a DIV
- Remove all special characters except space from a string using JavaScript
- How to use the command update-alternatives –config java
- How to Scroll Down – JQuery
- How can I process each letter of text using Javascript?
- What is the difference between a heuristic and an algorithm?
- Highlight a word with jQuery
- Javascript: ‘window’ is not defined
- Normalizing a list of numbers in Python
- Fire oninput event with jQuery
- Fastest way to extract frames using ffmpeg?
- what is the difference between bisizeimage , bisize and bfsize?
- javascript includes() case insensitive
- How to create a hidden in JavaScript?
- Reading local text file into a JavaScript array
- Trigger refresh for new media manager in 3.5
- Reset Undo on the tinymce editor
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Handling an Ajax form submit
- JavaScript in page doesn’t open new window [closed]
- How to localize value of posts
- Modifying JS files in Child-theme
- Why does this Quick Edit checkbox save the value only when unchecked?
- wp_enqueue_script adds only the first script
- JavaScript and images files are not recognized
- Dynamically insert values in a WordPress SelectControl Options field
- Vimeo froogaloop
- Putting PHP variables into javascript [duplicate]
- can a buttongroup have a label?
- Simple JS function Not Working
- InnerBlocks restricting does not work on nested blocks
- Get Required Assets (JS, CSS etc) for post using REST API
- Angular integration with homepage
- Seperate functions.php for part of site
- How to get specific string/value from an array? php [closed]
- Background Music WP [closed]
- Why i can’t get custom fields value or post ID via Ajax?
- How to reference PHP in Javascript
- html form: redirect page after form completes submit function and posts data
- Putting custom html/js page into Elementor as it’s own block
- Redirect after scrolling the page
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Drag-to-Scroll Landingpage
- Easiest way to find JS conflicts
- Javascript scroll eventHandler only working when I’m logged in in WordPress
- XMLHttpRequest of admin data to public
- How to call a function from functions.php with ajax?
- Display three sequential posts on each page load, without repeating previous
- Redirect sub-page URLs to parent without changing URL
- How to create a dashboard for logged-in users with custom functionality? [closed]
- Showing a link with Javascript based on log-in status
- Trying to fix multiple category drop down
- List.js inside WordPress widget
- How to make a Post Tag primary?
- Get all users from role and add to dropdown (select) – wordpress, javascript
- How can I use AJAX in child theme template?
- WordPress enque the same script causes the setInterval not to work