Posted inTechnology / Ajax / JavaScript / jQuery / Laravel

jQuery Get Selected Option From Dropdown Example

jQuery Get Selected Option From Dropdown Example

Today, We want to share with you jQuery Get Selected Option From Dropdown Example.
In this post we will show you jQuery Get Selected Option From Dropdown Example, hear for jQuery Get Selected Option From Dropdown Example we will give you demo and example for implement.
In this post, we will learn about jQuery Get Selected Option From Dropdown Example with an example.

Using jQuery function, just simple add a change event and get selected option value or text name within events that handler.

Use the jQuery.val() function used for select each elements.

The .val() function or method is simple used to get each data the values of form elements(HTML select option) such as input type, select elements and textarea.

Syntax of jQuery :selected Selector

Select option the pre-selected itemlists in a drop-down list

 $(":selected")

The jQuery :selected selector select element can be used in conjugation data with the val() function or method to find the selected HTML element option value in a select box get value or dropdown list.

HTML Code For : jquery get selected option text Dropdown




jquery Code

var PageName = $('#productptask').find(":selected").text();
console.log("pname="+PageName);

Using Javascript :

var PageName = document.getElementById('productptask').value = 'seven';
console.log("pname="+PageName);

or
// Use first select HTML element
var el = document.getElementsByTagName('select')[0]; 
el.selectedIndex = 3;

Example 2 : – Get Selected value of dropdown in jquery on change

HTML part for – jquery get selected option value onchange


Script : jQuery

$(function() {
  $("#productptask").on("change", function() {
    $("#responsedata").text($("#productptask").val());
  }).trigger("change");
});

View Demo

We hope you get an idea about jQuery Get Selected Option From Dropdown Example
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype