Presenting a dynamic selection of files from a database in a dropdown menu with looping functionality using Laravel

I have a dropdown menu that I want to use to display input files from the database based on the selection made.

Here is the scenario: When a dropdown option is chosen, it should show input files derived from the "loop_atachment" table (based on the selected groupid).

See the image of the database here

Below is the code snippet:

Dropdown in blade :

<select id="groupid" name="groupid" class="form-control">
    <option value="">Choose</option>
    <option value="1">General</option>
    <option value="2">Golf Club</option>
</select>

Input file will be displayed here when a dropdown option is selected:

<div class="form-group">
  <label class="control-label">loop attachment</label>
   {{ Form::file('image', array(), null, array('id' => 'image', 'class'=>'form-control'))  }}
</div>

Javascript/ajax :

 $('#groupid').on('change', function(){
    $.post('{{ URL::to('lender/dynamic') }}', {type: 'loop_attachment', id: $('#groupid').val()}, function(e){
        $('#image').html('');
        $('#image').html(e);
        });
    });

Controller :

public function postDynamic(Request $request) 
{
    switch(Input::get('type')):
        case 'loop_attachment':
            $return = '';
            foreach(Loop_attachment::where('groupid', Input::get('id'))->get() as $row) 
                $return .= "$row->doctype <br><input type='file' style='margin-bottom:1px;' name='$row->id' id='image'><br>";
            return $return;
        break;
    endswitch;         
}

A file input box should be displayed upon selecting a dropdown option, but currently, it's not working. Any help would be greatly appreciated. Thank you!

Answer №1

After revising my code for the question "How can I display the input file when selecting it from a dropdown menu?", here is the updated version:

<div class="form-group"> <label class="control-label" id="image">loop attachment</label> </div>

Surprisingly, this modification worked like a charm. All that's left now is to add some aesthetic touches for styling :)

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

Missing ghost image appears when you drag and drop the file

New to JavaScript... As a rookie in coding, I often get interesting requests from my partner who is a kindergarten teacher. Recently, she asked me to create a "Function Machine" for her classroom activities. With some trial and error, I managed to put tog ...

Implementation of async operations using while loop in Node.js

I'm facing an issue with my code snippet. Here's what it looks like: Rating.find({user: b}, function(err,rating) { var covariance=0; var standardU=0; var standardV=0; while (rating.length>0){ conso ...

Tips on enlarging the header size in ion-action-sheet within the VueJS framework of Ionic

Recently I started using Vue along with the ionic framework. This is a snippet of code from my application: <ion-action-sheet :is-open="isActionSheetOpen" header="Choose Payment" mode="ios" :buttons="buttons&qu ...

How can you initiate the wizard sequence again in TelegrafJS?

I've created a handler function for "/start" that leads to the wizard scene. Now, I have a message with an inline_keyboard containing a button labeled "redo". When I click on the "redo" button, I want it to restart the entire scene, basically initiat ...

Retrieve information from the identical registration form in Codeigniter

https://i.stack.imgur.com/FWTIf.png The student registration form includes fields for father and mother information in the student table, while guardian information is stored in a separate guardians table. When selecting "Father" in the "Guardian Informat ...

What is the best method to incorporate JavaScript into all pages of a website?

Interested in incorporating "Google Analytics" on your website? I just finished configuring my Google Analytics, but the final step is to insert the tracking code into every page I want to track. The code provided is: <script> (function(i,s,o,g,r ...

What is the correct way to detach and eliminate shared memory between two processes in PHP?

I came up with a method to handle asynchronous tasks in PHP, and so far it has been working really well. The concept is based on utilizing three extensions: PCNTL, POSIX, and Semaphore. In order to maintain complete control over both the master process a ...

"Clicking on a jQuery div will cause it to slide down, and clicking again

I am currently working on this code snippet: $("#right").click(function() { $("#signin").stop().slideDown(300); }); At the moment, it drops down when clicked, but I would like it to slideUp() when clicked again. Your help is appreciated. On a relate ...

What are the steps to update your profile picture using Angular?

In my Angular 6 application, I am implementing an image upload feature with the following code: Html: <img [src]="url ? url : 'https://www.w3schools.com/howto/img_avatar.png'"> <br/> <input type='file' (change)="onSelec ...

Integrate AngularJS with Laravel for efficient routing management

In my current web app project, I am utilizing AngularJS and Laravel for the development. Below is a breakdown of how my routing is set up: AngularJS: angular.config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRo ...

Adding an object in Laravel relationships can be achieved by utilizing the relationship methods provided

How can I include additional objects in a Laravel relationship when fetching data? This is my code snippet: $list = new self; $list = $list->where('uuid', $uuid); $list = $list->where('user_id', $user->id)->orWhere('to ...

Repairing the Performance of the 'Save' Feature

Can the 'Save' button in my code save team assignments for players selected using drag and drop? I'm considering using localStorage, but unsure about implementation. Note: To run the code properly, copy it as an HTML file on your computer. ...

Creating an HTML table with a PHP loop

I executed a MySQL query to populate an array: if ($result) { $foundResult = true; foreach ($result as $row) { array_push($searchResultAccount,$row->Account); array_push($searchResultUsername,$row->Username); array_pu ...

Integrate Tailwind CSS into the bundled JavaScript file

Is there a way to integrate tailwind css into bundle js effectively? Take a look at this example involving vue 3 and tailwind 3 https://github.com/musashiM82/vue-webpack. Upon executing npm run build , it generates 3 files: app.js ABOUTPAGE.js app.6cba1 ...

What is the process for obtaining the hash of every hyperlink?

I'm currently working on implementing an active link state based on scroll position for each section. My goal is to extract the hash value from the link. The issue I'm facing is that when I run the line 'console.log($(this).eq(i).hash);&ap ...

Methods to fill a data table cell

I have recently created a table and I am facing an issue in populating the tds cells using JavaScript. The data for the table is coming from the server. Here's my table: <table id="report" class="infoRecurso" id='testExportId' style="wid ...

Using JavaScript to redirect to a different page while passing parameters

I've been experimenting with passing parameters from one ASP.NET page to another within our website by using JavaScript, jQuery, Ajax, Fetch, etc., and then capturing this parameter on the Load event of the redirected page using JavaScript. I'm u ...

How to turn off automatic formatting in CKEditor

Whenever data is entered into a field using CKEditor, the Save button becomes enabled. However, if I programmatically set data into the field using Javascript, the Change event always triggers causing the Save button to remain enabled even if the field is ...

Attempting to locate the precise jQuery selector for a specific element

Let me show you how I've set up my markup: <li class="websites" id="3"> <span class="id">3</span> <span><a href="http://www.google.com"><span class="url">www.google.com</span></a></span> ...

What is the best way to handle binary files (such as images or audio) when serving them from a RESTful API that was built using

Exploring the most effective way to deliver files or bundles of files via a RESTful API. Considering options: Base64_encode files and include in JSON response Provide file links within JSON response Priority: Private access for certain files requiring ...