Topic: Material select retrieve option value

dlan pro asked 6 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


Jakub Strebeyko staff answered 6 years ago


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

dlan pro commented 6 years ago

Yes, it has thank you.

Adam Stapleton pro answered 6 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 6 years ago

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


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

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags