Avatar of Stephen Forlance
Stephen Forlance
 asked on

Getting selected value using Jquery

Hi all, I have this simple form which triggers a jquery function when a change happens, but how can I get the actual selectedindex value?

$(document).ready(function() {
  $('#form select').change(function() {

    //var strChosen = $(this).attr('id');
    var strChosen = $(this).attr('id');
		<form id="form">
<div><p>			Question 1: Name</p>
<input type="textfield" name="name" id="name">

<div> Question 2: Pet Type
	<select id="pet">
		<option value=""></option>
		<option value="Dog">Dog</option>
		<option value="Cat">Cat</option>

<div> Question 3: Dog Breed
	<select id="breed" name="breed">
				<option value=""></option>
		<option value="Bernese">Bernese</option>
		<option value="American Cocker Spaniel">American Cocker Spaniel</option>

<div> Question 4: Cat Breed
	<select id="catbreed">
				<option value=""></option>
		<option value="Black and White">Black and White</option>
		<option value="Tabby">Tabby</option>

Open in new window


Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Stephen Forlance

Thank you!
Julian Hansen

You are welcome.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy