Material select retrieve option value


Topic: Material select retrieve option value

dlan pro asked 7 years ago

Hi,I'm trying to retrieve the value of the options that I have specified for a material select input field. After a lot of trial and error and a lack of documentation about this topic I'm still not getting the wanted result.Snippet of my initialization:

<div class="col">
    <div class="md-form mt-0">
    <select class="mdb-select" id={{$id}}>
        @if(isset($options) && count($options) > 0)
            @foreach($options as $option)
                <option value="{{$option->id}}">{{$option->value}}</option>
            @endforeach
        @else
            <option value="INVALID">No options available for this user</option>
        @endif
    </select>
    <label>{{$label}}</label>
    </div>
</div>

I would like to be able to get the value of the selected option in JQuery but I see no way to access this.Thanks in advance


Adam Stapleton pro answered 7 years ago

You should be able to access the selected value in the standard way, I just use something like the below when accessing the values in my application.
$('#select-id').val();
This would get the option items individually from the select for you to do as you wish with.
$('#select-id option:selected)

dlan pro commented 7 years ago

Thank you this works, think I was searching it too far.

Jakub Strebeyko staff answered 7 years ago

Hi there dlan, Welcome to the Support Board! Did the response above help? With Best Regards, Kuba

dlan pro commented 7 years ago

Yes, it has thank you.

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No