Get data from DB based and display in textbox on selected values. laravel 5.7












0















I had to display data on textbox on change of select box but it will not work & also control not going to ajax url.



HTMl code:



<select class="form-control" name="product_title" id="product_title">
@foreach($product_title as $id => $p_title )
<option value="{{ $id }}">{{ $p_title }}</option>
@endforeach
</select>
<input type="text" class="form-control" name="product_price" id="product_price">
<input type="text" class="form-control" name="product_quantity" id="product_quantity">


Js:



<script>
$(document).ready(function(){
$("#product_title").change(function(){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: "{{ url('/productdetails') }}",
method: 'get',
data: {
id: jQuery('#product_title').val()
},
success: function(result){
jQuery('#product_price').html(result.product_price);
jQuery('#product_quantity').html(result.product_quantity);

}});

});
});
</script>


route:
Route::get('/productdetails', 'ProductController@getProduct');



  public function getProduct(Request $req)
{
$product = product::find($req->id)->first(); // Product is the model
//dd($product);
if ($product)
{
return response()->json(['product_price' => $product->product_price,'product_quantity' => $product->product_quantity]);
}
}


Database table name is product with attribute id,product_title,product_price,quantity.When i select title value from select box related value product_price,quantity from database will display in textbox.










share|improve this question


















  • 1





    Maybe you can explain the thing the you want in more detail...

    – Milkmannetje
    Dec 31 '18 at 11:20
















0















I had to display data on textbox on change of select box but it will not work & also control not going to ajax url.



HTMl code:



<select class="form-control" name="product_title" id="product_title">
@foreach($product_title as $id => $p_title )
<option value="{{ $id }}">{{ $p_title }}</option>
@endforeach
</select>
<input type="text" class="form-control" name="product_price" id="product_price">
<input type="text" class="form-control" name="product_quantity" id="product_quantity">


Js:



<script>
$(document).ready(function(){
$("#product_title").change(function(){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: "{{ url('/productdetails') }}",
method: 'get',
data: {
id: jQuery('#product_title').val()
},
success: function(result){
jQuery('#product_price').html(result.product_price);
jQuery('#product_quantity').html(result.product_quantity);

}});

});
});
</script>


route:
Route::get('/productdetails', 'ProductController@getProduct');



  public function getProduct(Request $req)
{
$product = product::find($req->id)->first(); // Product is the model
//dd($product);
if ($product)
{
return response()->json(['product_price' => $product->product_price,'product_quantity' => $product->product_quantity]);
}
}


Database table name is product with attribute id,product_title,product_price,quantity.When i select title value from select box related value product_price,quantity from database will display in textbox.










share|improve this question


















  • 1





    Maybe you can explain the thing the you want in more detail...

    – Milkmannetje
    Dec 31 '18 at 11:20














0












0








0








I had to display data on textbox on change of select box but it will not work & also control not going to ajax url.



HTMl code:



<select class="form-control" name="product_title" id="product_title">
@foreach($product_title as $id => $p_title )
<option value="{{ $id }}">{{ $p_title }}</option>
@endforeach
</select>
<input type="text" class="form-control" name="product_price" id="product_price">
<input type="text" class="form-control" name="product_quantity" id="product_quantity">


Js:



<script>
$(document).ready(function(){
$("#product_title").change(function(){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: "{{ url('/productdetails') }}",
method: 'get',
data: {
id: jQuery('#product_title').val()
},
success: function(result){
jQuery('#product_price').html(result.product_price);
jQuery('#product_quantity').html(result.product_quantity);

}});

});
});
</script>


route:
Route::get('/productdetails', 'ProductController@getProduct');



  public function getProduct(Request $req)
{
$product = product::find($req->id)->first(); // Product is the model
//dd($product);
if ($product)
{
return response()->json(['product_price' => $product->product_price,'product_quantity' => $product->product_quantity]);
}
}


Database table name is product with attribute id,product_title,product_price,quantity.When i select title value from select box related value product_price,quantity from database will display in textbox.










share|improve this question














I had to display data on textbox on change of select box but it will not work & also control not going to ajax url.



HTMl code:



<select class="form-control" name="product_title" id="product_title">
@foreach($product_title as $id => $p_title )
<option value="{{ $id }}">{{ $p_title }}</option>
@endforeach
</select>
<input type="text" class="form-control" name="product_price" id="product_price">
<input type="text" class="form-control" name="product_quantity" id="product_quantity">


Js:



<script>
$(document).ready(function(){
$("#product_title").change(function(){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: "{{ url('/productdetails') }}",
method: 'get',
data: {
id: jQuery('#product_title').val()
},
success: function(result){
jQuery('#product_price').html(result.product_price);
jQuery('#product_quantity').html(result.product_quantity);

}});

});
});
</script>


route:
Route::get('/productdetails', 'ProductController@getProduct');



  public function getProduct(Request $req)
{
$product = product::find($req->id)->first(); // Product is the model
//dd($product);
if ($product)
{
return response()->json(['product_price' => $product->product_price,'product_quantity' => $product->product_quantity]);
}
}


Database table name is product with attribute id,product_title,product_price,quantity.When i select title value from select box related value product_price,quantity from database will display in textbox.







mysql laravel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 31 '18 at 11:14









smita patil smita patil

85




85








  • 1





    Maybe you can explain the thing the you want in more detail...

    – Milkmannetje
    Dec 31 '18 at 11:20














  • 1





    Maybe you can explain the thing the you want in more detail...

    – Milkmannetje
    Dec 31 '18 at 11:20








1




1





Maybe you can explain the thing the you want in more detail...

– Milkmannetje
Dec 31 '18 at 11:20





Maybe you can explain the thing the you want in more detail...

– Milkmannetje
Dec 31 '18 at 11:20












2 Answers
2






active

oldest

votes


















0














Looks like issue is on success function lines. html is not useful for assign value to text. it is used to echo html. instead you can use val() like following.



jQuery('#product_price').val(result.product_price);
jQuery('#product_quantity').val(result.product_quantity);



Hope it helps. happy coding.






share|improve this answer
























  • ajax response not working

    – smita patil
    Dec 31 '18 at 11:35











  • you mean to say ajax is not going inside controller method ? can you dd product there in controller ?

    – Kul
    Dec 31 '18 at 11:36













  • yes ajax not working

    – smita patil
    Dec 31 '18 at 11:37













  • what is error there on ajax?

    – Kul
    Dec 31 '18 at 11:41











  • control is not passed in ajax coding so error will not getting

    – smita patil
    Dec 31 '18 at 11:44





















0














you can use simple without jquery like as follow



<select>
foreach($result as $key => $value)
{
echo "<option value=".$your_id_variable.">".$your_display_variable."</option>";
}







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986786%2fget-data-from-db-based-and-display-in-textbox-on-selected-values-laravel-5-7%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Looks like issue is on success function lines. html is not useful for assign value to text. it is used to echo html. instead you can use val() like following.



    jQuery('#product_price').val(result.product_price);
    jQuery('#product_quantity').val(result.product_quantity);



    Hope it helps. happy coding.






    share|improve this answer
























    • ajax response not working

      – smita patil
      Dec 31 '18 at 11:35











    • you mean to say ajax is not going inside controller method ? can you dd product there in controller ?

      – Kul
      Dec 31 '18 at 11:36













    • yes ajax not working

      – smita patil
      Dec 31 '18 at 11:37













    • what is error there on ajax?

      – Kul
      Dec 31 '18 at 11:41











    • control is not passed in ajax coding so error will not getting

      – smita patil
      Dec 31 '18 at 11:44


















    0














    Looks like issue is on success function lines. html is not useful for assign value to text. it is used to echo html. instead you can use val() like following.



    jQuery('#product_price').val(result.product_price);
    jQuery('#product_quantity').val(result.product_quantity);



    Hope it helps. happy coding.






    share|improve this answer
























    • ajax response not working

      – smita patil
      Dec 31 '18 at 11:35











    • you mean to say ajax is not going inside controller method ? can you dd product there in controller ?

      – Kul
      Dec 31 '18 at 11:36













    • yes ajax not working

      – smita patil
      Dec 31 '18 at 11:37













    • what is error there on ajax?

      – Kul
      Dec 31 '18 at 11:41











    • control is not passed in ajax coding so error will not getting

      – smita patil
      Dec 31 '18 at 11:44
















    0












    0








    0







    Looks like issue is on success function lines. html is not useful for assign value to text. it is used to echo html. instead you can use val() like following.



    jQuery('#product_price').val(result.product_price);
    jQuery('#product_quantity').val(result.product_quantity);



    Hope it helps. happy coding.






    share|improve this answer













    Looks like issue is on success function lines. html is not useful for assign value to text. it is used to echo html. instead you can use val() like following.



    jQuery('#product_price').val(result.product_price);
    jQuery('#product_quantity').val(result.product_quantity);



    Hope it helps. happy coding.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 31 '18 at 11:29









    KulKul

    1469




    1469













    • ajax response not working

      – smita patil
      Dec 31 '18 at 11:35











    • you mean to say ajax is not going inside controller method ? can you dd product there in controller ?

      – Kul
      Dec 31 '18 at 11:36













    • yes ajax not working

      – smita patil
      Dec 31 '18 at 11:37













    • what is error there on ajax?

      – Kul
      Dec 31 '18 at 11:41











    • control is not passed in ajax coding so error will not getting

      – smita patil
      Dec 31 '18 at 11:44





















    • ajax response not working

      – smita patil
      Dec 31 '18 at 11:35











    • you mean to say ajax is not going inside controller method ? can you dd product there in controller ?

      – Kul
      Dec 31 '18 at 11:36













    • yes ajax not working

      – smita patil
      Dec 31 '18 at 11:37













    • what is error there on ajax?

      – Kul
      Dec 31 '18 at 11:41











    • control is not passed in ajax coding so error will not getting

      – smita patil
      Dec 31 '18 at 11:44



















    ajax response not working

    – smita patil
    Dec 31 '18 at 11:35





    ajax response not working

    – smita patil
    Dec 31 '18 at 11:35













    you mean to say ajax is not going inside controller method ? can you dd product there in controller ?

    – Kul
    Dec 31 '18 at 11:36







    you mean to say ajax is not going inside controller method ? can you dd product there in controller ?

    – Kul
    Dec 31 '18 at 11:36















    yes ajax not working

    – smita patil
    Dec 31 '18 at 11:37







    yes ajax not working

    – smita patil
    Dec 31 '18 at 11:37















    what is error there on ajax?

    – Kul
    Dec 31 '18 at 11:41





    what is error there on ajax?

    – Kul
    Dec 31 '18 at 11:41













    control is not passed in ajax coding so error will not getting

    – smita patil
    Dec 31 '18 at 11:44







    control is not passed in ajax coding so error will not getting

    – smita patil
    Dec 31 '18 at 11:44















    0














    you can use simple without jquery like as follow



    <select>
    foreach($result as $key => $value)
    {
    echo "<option value=".$your_id_variable.">".$your_display_variable."</option>";
    }







    share|improve this answer




























      0














      you can use simple without jquery like as follow



      <select>
      foreach($result as $key => $value)
      {
      echo "<option value=".$your_id_variable.">".$your_display_variable."</option>";
      }







      share|improve this answer


























        0












        0








        0







        you can use simple without jquery like as follow



        <select>
        foreach($result as $key => $value)
        {
        echo "<option value=".$your_id_variable.">".$your_display_variable."</option>";
        }







        share|improve this answer













        you can use simple without jquery like as follow



        <select>
        foreach($result as $key => $value)
        {
        echo "<option value=".$your_id_variable.">".$your_display_variable."</option>";
        }








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 12:40









        RamRam

        397




        397






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986786%2fget-data-from-db-based-and-display-in-textbox-on-selected-values-laravel-5-7%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas