select object selected text
Posted: Wed May 23, 2018 10:40 am
I have a Select Object (ID: select_field) with multiple set to Yes. Before saving the record, I check if the selected option contains a specific text.
As soon as the text contains a space, indexOf() always returns -1.
This works when I pass a string without spaces to indexOf()
This doesn't work when I pass a string with spaces to indexOfO
As soon as the text contains a space, indexOf() always returns -1.
This works when I pass a string without spaces to indexOf()
Code: Select all
var s = $('#select_field').find("option:selected").text(); // s = "123 Hello World"
var i = s.indexOf('Hello');
alert(i);
Code: Select all
var s = $('#select_field').find("option:selected").text(); // s = "123 Hello World"
var i = s.indexOf('Hello World');
alert(i);