Javascript doesn’t work in file blade Laravel


#ask Can anyone help me? I don’t understand why my script code doesn’t work.I want fill text input after click button and show alert but it’s not working.

In the app.blade.php file I have added this

<head>
      <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">

<title>MHYSA LEARNING</title>
</head>
<body>
    <div id="app">

       <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
               ..........
       </nav>
     
        <main class="py-4">
                 @yield('content')    
        </main>

    </div>

    @yield('scripts')

</body>

this my payment.blade.php

   @extends('layouts.app')

   @section('content')
   <div class="container">
    ....

       <table class="trip-informations">
                <tr>
                      <th>
                        <div class="container">
                             <form method="POST"  action="{{ route('coupon.store') }}">
                                @csrf
                                <div class="row align-items-start">
                                
                                    <input class="col-4 widget-square1"style="font-weight: 300;font-size:16px;margin-left:5px;padding:5px" name="coupon_code" id="coupon_code">
                                      </input>
                                      <button class="col-3 widget-square2"style="font-weight: 100px;font-size:10x;color:#fff" id="coupon_button"> Masukkan</button>
                                    
                                 
                                  </div>
                                    
                            </form>
                      </th> 
                  </tr>

       </table>

        ......
    </div>
   @ensection

  @section('script')

 <script type="text/javascript" charset="utf-8">
  $('#coupon_button').on('click', function(){

    var coupon_code = $('#coupon_code').val();
    alert('tes');

  });
   </script>


@endsection

is there something wrong with my code because the test alert does not appear and filling input text after click button also doesn’t work

Source: JavaSript – Stack Overflow

August 14, 2021
Category : News
Tags: autofill | javascript | laravel | php | user-input

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.