John Davidson

javascript - how to get a value from a form blade index to jquery from blade edit?

0 comments
Message:


i want to edit from one annonces, then the form of balde edit changes according to souscotegory_id, me i want to know souscategory_id comes from blade index to jquery from blade edit, in my case it gives me null.


index.blade.php


<a href="{{ url('annonces/'.$annonce->id.'/edit') }}" class="btn btn-primary btn-sm"><span class="fa fa-edit"></span></a>

AnnonceController.php


 public function edit($id)
{
$annonce = Annonce::find($id);
return view('annonces.edit')->with([
'annonce' => $annonce
]);
}

edit.blade.php


let souscategory_id = window.sessionStorage.getItem('souscategory_id');
alert(souscategory_id);


My Answer:
In order to pass the `souscategory_id` from the blade index to jQuery in the blade edit, you can use a hidden input field in your form in the blade index to store the value of `souscategory_id`. Then, you can access this hidden input field value in your jQuery script in the blade edit.

Here is an example of how you can achieve this:

1. In your `index.blade.php` file, add a hidden input field to store the `souscategory_id` value:

html



2. In your jQuery script in the `edit.blade.php` file, you can access the value of `souscategory_id` using the following code:

javascript
$(document).ready(function() {
var souscategory_id = $('#souscategory_id').val();
console.log(souscategory_id); // This will log the value of souscategory_id to the console
});


By following these steps, you should be able to pass the `souscategory_id` value from the blade index to jQuery in the blade edit.

Rate this post

5 of 5 based on 2464 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us