Home > Software engineering >  Jquery to change form action and, Pass user id through action
Jquery to change form action and, Pass user id through action

Time:03-07

I have a modal where a user fill the data and when user press the submit button, a id fetch from jQuery and save data in datable according to the user id. So, I have to fetch the id from jQuery and have to pass through PHP variable.

Here is my query for changing my form URL:

$('#get_form').attr('action', '{{ url("admin/report/update/"."$id="obj.data('id'))" }}');

And, here is my form

<form action="" id = "get_form" method="post"  enctype="multipart/form-data">

I am unable to set the URL perfectly.

CodePudding user response:

You're mixing blade with js. Try formatting the url like this:

const url = "{{ url('admin/report/update/:id') }}".replace(':id', obj.data('id'))
// generates admin/report/update/1 assuming obj.data('id') is equal to 1

$('#get_form').attr('action', url);

CodePudding user response:

 var id = $('some-id').val();  // a hidden value

 var url = "{{ url('admin/report/update/') }}"   id;

 $('#get_form').attr('action', url);
  • Related