Page 1 of 2

Get value from Select

Posted: Sat Mar 08, 2014 6:18 am
by Milton Davis

I am trying to alert a value from a Select menu.

I have tried both:
alert(JSON.stringify(Appery("Contact_Select").val()));

alert(Appery("Contact_Select").val());

but instead of getting the text of the selected element in Contact_Select I only get a " or ,


Get value from Select

Posted: Sat Mar 08, 2014 11:05 am
by Illya Stepanov

Hi Milton,

Have you tried with code.text();/code instead of code.val();/code


Get value from Select

Posted: Sat Mar 08, 2014 6:22 pm
by Milton Davis

Yes, that was returning all text labels for each item, not just the selected ones.


Get value from Select

Posted: Sat Mar 08, 2014 7:24 pm
by Illya Stepanov

You want to return only selected ones?


Get value from Select

Posted: Sat Mar 08, 2014 7:30 pm
by Milton Davis

Yes. The text or value from only the selected items.


Get value from Select

Posted: Sat Mar 08, 2014 8:42 pm
by Illya Stepanov

Try this way:
prealert(Appery('myselectmenu').find(':selected').text());/pre

  • where 'myselectmenu' is the name of your select component.

Get value from Select

Posted: Sat Mar 08, 2014 8:42 pm
by Milton Davis

This does not work either...

alert($("#Contact_Select option:selected").text());


Get value from Select

Posted: Sat Mar 08, 2014 8:50 pm
by Milton Davis

That worked! Thank you very much


Get value from Select

Posted: Mon Mar 10, 2014 8:03 pm
by Milton Davis

Any suggestions on how to make this return a comma seperated list? Right now it is returning multiple items but combining then into one string with no spaces.


Get value from Select

Posted: Tue Mar 11, 2014 1:20 pm
by Maryna Brodina

Hello!

To get array of all records use the following code:
prevar arr = [];
Appery('myselectmenu').find(':selected').each( function() {
arr.push($(this).val())
})/preAfter you get array you can expose it any way you need.