Guide on displaying a modal from a separate file onto my HTML page with Laravel and Ajax

In my project, I am utilizing Laravel and AJAX. Inside the index.blade.php file, I have the following code:

<a onclick="addForm()" class="btn btn-success " style="float:right;">Tambah</a>

Additionally, I have the following script:

<script type="text/javascript">
    function addForm(){
        save_method = "add" ;
        $('input[name=method]').val('POST') ;
        $('#myModal').modal('show') ;
        $('#myModal form')[0].reset() ;
        $('.modal-title').text('Tambah Kategori') ;
    }
</script>

Now, I want to call the modal from another file called form.blade.php, which is located in the same folder as index.blade.php. Here is an excerpt from my form file:

<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog modal-lg">
    <div class="modal-content">

        <form class="form-horizontal" data-toggle="validator" method="POST">
            {{ csrf_field() }} {{ method_field('POST') }}

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>

                <h3 class="modal-title"></h3>

            </div>

            <div class="modal-body">
                <input type="hidden" name="id" id="id">

                <div class="form-group">
                    <label for="nama" class="col-md-3 control-label">Nama</label>
                    <div class="col-md-6">
                        <input type="text" id="nama" class="form-control" name="nama" autofocus required>
                        <span class="help-block with-errors"></span>
                    </div>
                </div>


            </div>

            <div class="modal-footer">
                <button type="submit" class="btn btn-primary btn-save">Simpan</button>
                <button type="button" class="btn btn-warning" data-dismiss="modal">Batal</button>
            </div>
        </form>

    </div>
</div>

However, I am encountering an issue where my modal is not displaying. Can anyone provide insights on why this might be happening?

Answer №1

To ensure that your JavaScript has a reference to the necessary file, make sure to include your form.blade.php within your index.blade.php.

Laravel's Blade documentation provides detailed instructions on how to achieve this: https://laravel.com/docs/5.6/blade#including-sub-views

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

What is the best way to address the excess white space between an image and progress bar on larger screens while utilizing the Bootstrap Grid system?

https://i.sstatic.net/NXMNV.pngLet's begin by visualizing the concept through these images: In Picture (1), the progress bars are positioned below the image on medium to large screens, with the text aligned to its right. https://i.sstatic.net/Cw1aM.pn ...

What is the best way to pass the company ID in the controller?

Creating a new contact can be done through the form below Add New Contact @using (Html.BeginForm("Create", "Contact", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <fieldset> ...

The Power of Symfony Combined with jQuery's Data Handling Function

My app features an ajax navigation system. Each ajax link is given the class ajax, and the page it should load is stored in an aurl attribute, as shown below: <a class="ajax" aurl="/user/posts/3/edit">Edit Post</a> The element's aurl is ...

occupy the full width of the available screen space (from one end of the container to the other

Currently, I am utilizing the Flexbox enabled version of Bootstrap 4 Alpha 3. Check it out on Jsfiddle body { background-color: lightgreen; } [class^="col"] { background: gold; border: 1px solid tomato; } <link href="https://cask.scotch.io/boo ...

Sharing images

Sample Code: <form enctype="multipart/form-data"> <input id="upFile" class="upFile" type="file" size="0" name="file" accept="image/gif,image/jpeg,image/png"> <input type="submit" id="upFileBtn" class="upFile"> </form> A ...

Retrieve data from a MySQL database with multiple values stored in a single row

In my project, I have implemented a filter functionality using PHP and jQuery/AJAX, where my table of products is structured as follows: |id|status|name|colors_id| ------------------- | 1| 1 | toy| 1,4,7 | <-- these are the IDs of various filters, ...

Server becoming unresponsive following the cancellation of an AJAX call

In a specific scenario, my Ajax request to the server might take longer than usual (around 30-40 seconds). I am utilizing jQuery.ajax and specifying a timeout of 60 seconds. Consequently, if no response is received within this timeframe, the call gets canc ...

The breadth of the container

I am facing challenges in determining the setup of the content width with a fixed side panel. I want the side panel to maintain a set width regardless of the screen size, while the rest of the window accommodates the navbar, content, and footer. I have bee ...

Guide on how to save the selected user option in a PHP form

I'm having trouble getting the form to automatically set itself based on the state selected by the user from a drop-down menu of 50 states. The user's info, including their chosen state, is stored in an info array with $state. Everything else dis ...

Obtain date and currency formatting preferences

How can I retrieve the user's preferences for date and currency formats using JavaScript? ...

Leveraging jQuery.ajaxSetup for customizing beforeSend function and modifying outgoing data for AJAX requests

My goal is to develop a universal beforeSend function that modifies the data sent by each jQuery.ajax call. This will allow me to include a custom variable for tracking purposes in every request, regardless of the order they are sent in. For instance, let ...

When utilizing ng-content alongside *ngtemplateOutlet, the content does not appear visible within the DOM

I'm working with three Angular components - a base component and two child components (child1 and child2). The structures are as follows: child1.component.html <ng-template #child1Template> <div> <h1>CHILD 1</h1> ...

Challenges arise when attempting to pass array data from Ajax to Google Maps

I'm facing an issue with my Google map. I have a data array that is dynamically returned, and I want to use it to add markers to the map. However, the markers don't work when I pass the data variable to the add_markers() function. It only works i ...

Having difficulty retrieving the value from summernote after an ajax update

Whenever I click the edit button (using a modal with Bootstrap), all values are retained except for the textarea with Summernote. If you input something into Summernote and then cancel, your value does not disappear... it should be clear. I apologize for ...

Is it possible to utilize the ternary operator to handle classnames when working with CSS modules?

I am experiencing difficulty implementing a styling feature using the ternary operator within an element's className. My goal is to have three buttons that render a specific component when clicked. Additionally, I want to change the background color ...

What is the method for adjusting the border color of an ng-select component to red?

I am having an issue with the select component in my Angular HTML template. It is currently displaying in grey color, but I would like it to have a red border instead. I have tried using custom CSS, but I haven't been able to achieve the desired resul ...

Adjust the class of the iframe element when clicked

I am attempting to change the class of an iframe (soundcloud embedded track) when it is clicked, in order to apply different properties. However, my code doesn't seem to be working as expected. Here is what I have: Here is a snippet from my index.htm ...

Tips for incorporating text into slider images

I need help adding text to my image slider. The slider is functioning properly, but I want text to accompany each image and I'm not sure how to achieve this. Below is the HTML code I have: <section id="banner"> <div class="banner-bg"&g ...

Struggling to click on a link while viewing the site on your mobile device?

Recently dove into the world of implementing mobile responsive design for a website I've been working on. While conducting some testing, I observed that the main tabs which direct users to different sections of the site, normally easy to click on desk ...

What is preventing my CSS Animation from activating on my website?

Is there something in the code preventing the animation from working properly? .projectLinks a{ background-color: var(--secondary-color); color: var(--main-color); padding: 2px 4px 4px 4px; border-radius: 15px; margin-right: 25px; text-decorati ...