WebDevB
WebDevB

Reputation: 492

Laravel 4 - Assign OnChange to Form::select

Is there a way of assigning an OnChange event to a Form::Select field?

I've managed to get around it at the moment but it's very messy and I'd like to change it so all my ajax requests are within one file...

Anyone else come across this?

Thanks.

Upvotes: 5

Views: 22310

Answers (3)

ganji
ganji

Reputation: 854

Right way is here:

{!! Form::select('id' => 'some-id', null, ['onchange'=>"alert(this.value);" ,'required']) !!}

Upvotes: 0

Adrian Bartholomew
Adrian Bartholomew

Reputation: 2632

The Laravel 5 way would be:

{!! Form::select( 'name', $options, 'default', array('onchange' => 'doSomething(this)') ) !!}

Upvotes: 2

WebDevB
WebDevB

Reputation: 492

Managed to fix it guys.

{{ Form::select('name', $options, 'default', array('id' => 'some-id'); }}

Then just the ID to assign the onChange event in your JS:

$(function(){
   $('some-id').change(function(e) {
    //perform AJAX call
   });
});

Upvotes: 3

Related Questions