简体   繁体   中英

Set background-color to div from form in another blade

My project contains index.blade.php and create.blade.php. In create.blade.php is a form for creating divs that are listed in the index.blade.php, through the form I need to pass the background-color for each div made, options red, yellow and green color.

My create.blade.php code:

<form action="{{url('warehouse')}}" method="post">
@csrf
<label for="name" style="padding-right:20px">Name</label>
<input type="text" id="name" name="name" style="padding-right:50px; margin-bottom:10px" placeholder="Name"><br>
<label for="supplier" style="padding-right:2px">Supplier</label>
<input type="text" id="supplier" name="supplier" style="padding-right:50px; margin-bottom:10px"
    placeholder="Supplier"><br>
<label for="type" style="padding-right:28.5px">Type</label>
<input type="text" id="type" name="type" style="padding-right:50px; margin-bottom:10px" placeholder="Type"><br>
<label for="url" style="padding-right:41.8px">Url</label>
<input type="text" id="url" name="url" style="padding-right:50px; margin-bottom:10px" placeholder="Url"><br>
<label for="color">Color</label>
<select id="selector" name="color">
    <option value="" disabled selected hidden>Please Choose...</option>
    <option value="green">Green (ready for sale)</option>
    <option value="yellow">Yellow (in progress)</option>
    <option value="red">Red (new)</option>
</select>
<br>
<button type="submit" id="kreiraj_dugme_create" onclick="selectBackground()">Create/button>

And my index.blade.php code:

@foreach ($warehouses as $key => $warehouse)
<div class="brder1" draggable="true" ondragstart="drag(event,{{$key}})" id="{{$key}}">
    <h1 class="ime_palete">{{$warehouse->name}}</h1>
    <a class="link_palete" href="{{$warehouse->url}}" target="_blank">Link</a>
    <a class="edit_palete" href="{{url("warehouse/".$warehouse->id."/edit")}}">Edit</a>
    <a class="show_pallet" href="{{url("warehouse/".$warehouse->id)}}">Show</a>
    <form action="{{url("warehouse/".$warehouse->id)}}" method="post">
        @csrf
        @method('DELETE')
        <button type="submit" class="izbrisiDugme" onclick="remove()">Remove</button>
    </form>
</div>
@endforeach

</div>
<a class="create_palete" href="{{url("warehouse/create")}}">Create</a>

All I need is to set background-color from options to div brder1

You probably need to do something like this

with jQuery:

 $("#selector").change(function(){
   $(".brder1").css('background-color', $(this).val());
});

You can place the code within document ready. So snippet will look like as follows

$(document).ready(function(){
    $("#selector").change(function(){
        $(".brder1").css('background-color', $(this).val());
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM