If I use the first then I can get the value, but how to get the data-id?
var skola = $$('select[name=skola]').val() // this gets the right value
var userId = $$('select[name=skola]').data('id'); //this is not working...
<select id="skola" class="skola" name="skola">
<option value="">Select a school</option>
<option value="lindblomskolan" data-id="1">Lindblomskolan</option>
<option value="skolappen" data-id="2">Skolappen</option>
</select>
I have tried sooooooo many different variations, but no luck haha…
<option value="">Select a school</option>
<option value="lindblomskolan" data-id="1">Lindblomskolan</option>
<option value="skolappen" data-id="2">Skolappen</option>
var userId = $$(‘select[name=skola]’).data(‘id’); // userid=“0”
if you want to get the data-id from the selected option ,may you can try
var options= $(‘select[name=skola]’).find(‘option:selected’).data(‘id’);
but when using $$ ,it doesn’t work!
AND why not make good use of VALUE as it’s meant to?
Thanks but, It does´t work for me.
And if only $ works for you then you must have jQuery as well I guess?
I have tested all jQuery examples I have found with $$ but nothing is working, all I get is this error.
SyntaxError (DOM Exception 12): The string did not match the expected pattern.
Well I simply need to get more than one value from the select, both from the value and the data-id!