Avatar of Nathan Riley
Nathan RileyFlag for United States of America

asked on 

MultiSelect jquery Select Value

How can I select the values that are selected in this multiple select via jQuery?

<select id="gender" name="gender" multiple="multiple" style="width:90.4%; padding:5px; margin:5px; color:#000000; ">
    <option value="'M'">Male</option>
    <option value="'F'">Female</option>
</select>

Open in new window


I tried
gender: $("#gender").val()

Open in new window


Doesn't seem to work for some reason.
jQueryJavaScriptPHP

Avatar of undefined
Last Comment
Julian Hansen
Avatar of Nathan Riley
Nathan Riley
Flag of United States of America image

ASKER

Appears it is selecting my data but it's posting as an array versus just posting as 'M' or 'F'.  Anyway to stop it from creating an array?

The post value shows up like this when I vardump
array (size=1)
  0 => string ''M'' (length=3)

Not sure why it's turned into an array or adding additional quotes around it.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Anyway to stop it from creating an array?
... as opposed to? It is a multi-select control - how else is it going to capture the multiple values selected.

The post value shows up like this when I vardump
Where is your post code?

How are you sending this through?

gender: $("#gender").val()

Open in new window

Does not really make sense - in the context of the usual definition of gender?

The code is doing what it is supposed to do - tell us what you want it to do and we can take it from there.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo