How to send value from dropdown to the controller via ajax ?

Posted 5 days ago by PhoeniX5

Hello, how to get selected value from this dropdown like an : <input type="text" required="required" name="produit" class="form-control" /> when submiting the form ?

Here is my code :

<div class="form-group">
    <div class="dropdown">
        <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Choisissez le type du prduit<span class="caret"></span></button>
            <ul class="dropdown-menu">
                <li class="dropdown-header">Phone</li>
                <li><a href="#">Smartphone</a></li>
                <li><a href="#">Featurephone</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">TV</li>
                <li><a href="#">SmartTV</a></li>
                <li><a href="#">BasicTV</a></li>
                <li><a href="#">Demodulateur</a></li>
            </ul>
    </div>
</div>







$('#pr_form').on('submit', function(event){
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"{{ route('produit.upd') }}",
            method:"GET",
            data:form_data,
            dataType:"json",
            success:function(data)
            {
                if(data.error.length > 0)
                {
                    var error_html = '';
                    for(var count = 0; count < data.error.length; count++)
                    {
                        error_html += '<div class="alert alert-danger">'+data.error[count]+'</div>';
                    }
                    $('#form_output').html(error_html);
                }
                else
                {
                    $('#form_output').html(data.success);
                    $('#pr_form')[0].reset();
                    $('#pr_table').DataTable().ajax.reload();
                }
            }
        })
    });

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.