mercredi 31 mai 2017

How to apply a JS variable to a Laravel Form Action

I need to pass an AJAX variable into my view such that the form action executes correctly. Using Laravel 5.4. and my (abbreviated) view looks like this:

<div id="product_form"  class="form-horizontal">

    


    <div class=" form-group">
        <div class="col-sm-2  col-md-2"></div>
        <div class="col-sm-4 col-md-4"></div>
        <div class="col-sm-2 col-md-2"></div>
        <div class="col-sm-4 col-md-4"></div>
    </div>

My Ajax function is passing all the values into the form fields correctly, however I am struggling to get the product_id into the correct place in the action statement. Laravel expects to see a variable.

Ajax Code (abbreviated):

 select: function( event, ui ) {
        var product_id = ( ui.item.value );

        $.ajax({
            url: "product_fullsearch/"+product_id,
            dataType: "json",
            type:"GET",
            success: function (data) {
                $('#product_name').val(data[0].product_name);
                $('#product_id').val(data[0].product_id);
                $("#supplier_name").val(data[0].supplier_name);
                $("#supplier_id").val(data[0].supplier_id);
            }
        });//END AJAX

    } 

I saw this Pass JS variable to form action on SO and gave it a go, but I could not get it to work in a Laravel context.

What am I dong wrong ? Many thanks !



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qHu70w
via IFTTT

Aucun commentaire:

Enregistrer un commentaire