Issues with Laravel 5.8 and Bootstrap not functioning properly in Jquery

Check out this link for using Bootstrap Select. The code works perfectly in the view, but when I try to implement it with jQuery below, it doesn't work. Can someone help me fix this issue?

View Code:

<table id="tableAppointment" style="background-color:powderblue;">
     
    <tr>
        <th style="text-align:center;" colspan="1">NAME</th>
        <th style="text-align:center;" colspan="1">HSN/SAC</th>

        <th><a href="#" class="addRow btn btn-warning vertical-center"><i class="glyphicon glyphicon-plus">ADD</i></a></th>
    </tr>

    <tr>
        <td>
            <select class="selectpicker" data-live-search="true"  name="product_name[]">
               <option value=""></option>
                @foreach ($addnewitem as $key=>$addnewitems)
                    <option>{{$addnewitems->product_name}}</option> 
                @endforeach
            </select>
        </td>

        <td>
            <select class="selectpicker" data-live-search="true"  name="part_no[]">
                <option value=""></option>
                @foreach ($addnewitem as $key=>$addnewitems)
                    <option>{{$addnewitems->part_no}}</option> 
                @endforeach
            </select>
        </td>

        <td><a href="#" class="btn btn-danger "><i class="glyphicon glyphicon-remove">REMOVE</i></a></td>
    </tr>

</table>

<script type="text/javascript">

    $('.addRow').on('click',function(){
        addRow();
    });
    
    function addRow()
    {
    
        var tr = '<tr>' + '<td><select class="selectpicker" data-live-search="true"  name="product_name[]"><option value=""></option> @foreach ($addnewitem as $key=>$addnewitems)<option>{{$addnewitems->product_name}}</option>@endforeach </select></td>' + '<td><select class="selectpicker" data-live-search="true"  name="part_no[]"><option value=""></option> @foreach ($addnewitem as $key=>$addnewitems)<option>{{$addnewitems->part_no}}</option>@endforeach </select></td>' + '<td><a href="#" class="btn btn-danger remove"><i class="glyphicon glyphicon-remove">REMOVE</i></a></td>' + '</tr>';
        
        $('tbody').append(tr);
    };
    
    $('.remove').live('click', function(){
        var last = $('tbody tr').length;
        if(last == 1){
            alert("You can not remove the last row");
        } else {
            $(this).parent().parent().remove();
        }
    
    });

</script>

https://i.sstatic.net/wvLd1.jpg

Answer №1

When you click on $('.addRow'), make sure to refresh the selectpicker

If you need to update the bootstrap-select user interface after making changes to underlying values that impact the layout, you can use the render method.

$(document).on('click','.addRow',function(){
    addRow();
    $('.selectpicker').selectpicker('refresh');

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to activating automatic filling of usernames and passwords in web browsers

On my login page, I aim to make the user experience seamless by automatically filling in the username and password fields once a user has logged in for the first time. This way, when they return to the login page, all they have to do is click the login but ...

Is there a more effective method for positioning items in a navigation bar other than using padding-left?

Hey there, I've been working on this navigation bar for quite some time now and finally found a way to center the menu items. However, I want to make sure I'm doing it the right way. Does anyone have suggestions on how to center all the "li" elem ...

Did my code effectively block an XSS attack?

Recently, I was informed that my website has vulnerabilities to XSS attacks. In an effort to improve security, I have implemented the htmlspecialchars method as a preventive measure. Here is the function I created: function _e($string){ return htmlsp ...

How can I insert mock data into a datatable using Django?

I recently completed a small application using django. In order to implement datatables, I used the code from django_datatables_view.base_datatable_view import BaseDatatableView import. This datatable displays results directly from the queryset. I now h ...

Ensure selected language is maintained when refreshing or changing view by utilizing switch i18n functionality

Hello there, I am facing a challenge with "JavaScript Localization" on my website. The issue is that I cannot figure out how to prevent the DOM from prioritizing the local language of the browser and instead use the language set in the switch as a referenc ...

Guide to creating a versatile navigation bar using Bootstrap and HTML

I am looking to create a navigation menu that can be easily reused across multiple pages on my bootstrap/html website. Instead of duplicating code, I want to implement a solution for creating a reusable navigation menu in bootstrap/html. How can this be ...

Issues with Thunderbird not displaying copied HTML emails

Hello there amazing people at Stackoverflow. I need some assistance with HTML formatting. I am currently working on a bootstrap modal that is being dynamically modified through jQuery using the append() function. Check out the code snippet below: <div ...

Exploring the Power of Elasticsearch with Datatables

I'm attempting to utilize functions from an Elasticsearch instance in conjunction with datatables to exhibit results. Currently, I am only able to display 10 results, regardless of the query used. Even though there are 141,000 results in Elasticsearc ...

The scroll function remains unchanged when using overflow-y scroll and border radius

I need help with styling a div that will contain a large amount of text on my webpage. I want to use the overflow-y property for scroll, but the issue arises when trying to style the scroll bar with a radius. Check out this jsfiddle link for reference: ht ...

Difficulty arises when attempting to locate particular information within a Vue component using a method that is contained within the component

Currently, I am in the process of developing a request management system for the organization. The key requirements for this project include: Ability to add a new row for each new request. Dynamic generation of parameters based on the selected descriptio ...

Removing CSS errors from HTML files in Visual Studio Code on a Mac

Currently, I am utilizing Visual Studio Code on a Mac for writing AngularJS style HTML. Whenever I try to include an inline expression for a CSS value, I encounter an irritating red Intellisense error, as displayed in the screenshot provided below. It is w ...

The issue with uploading files through ajax and jquery persists

I need to send the form using ajax. The form includes a text input field and a file upload field. However, in the ajax page (formaction.php), the file details are not being received. HTML <form method="post" id="newform" enctype="multipart/form-data"& ...

What is the best way to deactivate the second selection option?

<select id="title0"> <option value="0">--- disable</option> <option value="1"> books</option> </select> <button id="save" type="submit">Save</button> <select id="title1"> <option value="0"& ...

When the LI element is clicked, it triggers the display of another LI element without affecting the rest of the

New to the web development scene and trying to figure out how to create a collapsible text feature using HTML, JavaScript, and JQuery. I've got the styling down but struggling with the scripting part. Here's an example of what I'm trying to ...

In Laravel 5.8, the sum function returns null instead of 0 when there is no data in the table

Question: $summary['total_cash'] = DB::table('wallets') ->select(DB::raw('SUM(amount) as total_cash')) ->where('payment_details','affil ...

Creating a navigation bar - using the LI tag with spaces between words causes text to wrap to the next line

Currently, I am in the process of creating a dynamic navigation bar for my website. In order to ensure that the elements within the navigation bar adjust automatically based on content, I have implemented the code below: .mytaboptions { position: rela ...

The jQuery tooltip fails to function properly after the AJAX content is loaded

I have been using a tooltip script that can be found at: This is the script I am using, with a few modifications: $(document).ready(function() { $("body").on("mouseover", ".tip_trigger", function(){ tip = $(this).find('.tip&apos ...

Tips for adjusting container wrapping to accommodate smaller window widths in bootstrap 4

Bootstrap 4 is still new to me, and I haven't had much experience working with Bootstrap 3 either. One issue I've encountered is that when I apply the class col-(breakpoint)-(span) to div elements, they don't automatically align in a single ...

Is there a way to conceal the scrollbar while still permitting scrolling?

I'm interested in creating a custom scrollbar, but in order to do so I need to hide the default scrollbar while still allowing scrolling functionality. I've attempted: overflow-y:hidden; but this method hides the scrollbar and prevents scrolli ...

Retrieve all attributes of an element with the help of jQuery

I am attempting to extract all the attributes of an element and display their names and values. For instance, an img tag may have multiple unknown attributes that I need to access. My initial idea is as follows: $(this).attr().each(function(index, element ...