Laravel modal hidden value to call routeStop setInterval call in JavaScriptWhich “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How do I check if an element is hidden in jQuery?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Sort array of objects by string property valueWhat is the difference between call and apply?Copy array by valueHow do I return the response from an asynchronous call?How get the ID of select value from a dropdownlist and send it to a modal in php with ajax?

Have astronauts in space suits ever taken selfies? If so, how?

Animated Series: Alien black spider robot crashes on Earth

"which" command doesn't work / path of Safari?

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

Did Shadowfax go to Valinor?

Is the month field really deprecated?

Relation between Frobenius, spectral norm and sum of maxima

Why not use SQL instead of GraphQL?

How do I create uniquely male characters?

Do VLANs within a subnet need to have their own subnet for router on a stick?

Is it possible to rebuild the bike frame (to make it lighter) by welding aluminum tubes

Writing rule which states that two causes for the same superpower is bad writing

Dragon forelimb placement

Show a continuous function with f(x)=y and f(y)=x has a fixed point.

What defenses are there against being summoned by the Gate spell?

TGV timetables / schedules?

If two metric spaces are topologically equivalent (homeomorphic) imply that they are complete?

Is the language p and n are natural numbers and there's no prime number in [p,p+n] belongs to NP class?

N.B. ligature in Latex

Has the BBC provided arguments for saying Brexit being cancelled is unlikely?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

Why are 150k or 200k jobs considered good when there are 300k+ births a month?



Laravel modal hidden value to call route


Stop setInterval call in JavaScriptWhich “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How do I check if an element is hidden in jQuery?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Sort array of objects by string property valueWhat is the difference between call and apply?Copy array by valueHow do I return the response from an asynchronous call?How get the ID of select value from a dropdownlist and send it to a modal in php with ajax?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a modal with a hidden field of my current id that I need.



I need to click a button in my modal to confirm if I should delete a user. I setup a form not sure if this is the best option and in javascript set the attr of form to the route but the route isn’t finding the correct path although in the URL it says it correctly what am I missing maybe the route should be in PHP instead of JS?



<div class="modal" id="mdelete" role="dialog" aria-labelledby="moddelete">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="moddelete">Confirm Delete</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete</p>
</div>
<div class="modal-footer">
<form method="POST" id="formdelete">
<input type="hidden" name="txtid" id="txtid" />
<input type="text" name="uid" id="uid" />
<button type="button" class="btn btn-danger " data-dismiss="modal">No</button>
<span class="text-right">
<button type="submit" class="btn btn-primary btndelete">Yes</button>
</span>
</form>
</div>
</div>
<a href=" route('users.show', $user->id) " class="btn btn-primary mr-2">Show</a>
<a href=" route('users.edit', $user->id) " class="btn btn-info text-white mx-2">Edit</a>
<button type="button" class="btn btn-danger ml-2" data-toggle="modal"
data-target="#mdelete" data-id="$user->id"
data-name="$user->username">Delete</button>

$(document).ready(function()
$('#mdelete').on('show.bs.modal', function (event)
var button = $(event.relatedTarget);
var userid = button.data('id');
var uname = button.data('name');
var modal = $(this);
modal.find('#txtid').val(userid);
modal.find('#uid').val(userid);
modal.find('.modal-body').text('Are you sure you want to delete ' + uname);
)
$('#formdelete').submit(function()
var userid = $('#txtid').val();
$('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");
$('#formdelete').submit();
);
);









share|improve this question






























    0















    I have a modal with a hidden field of my current id that I need.



    I need to click a button in my modal to confirm if I should delete a user. I setup a form not sure if this is the best option and in javascript set the attr of form to the route but the route isn’t finding the correct path although in the URL it says it correctly what am I missing maybe the route should be in PHP instead of JS?



    <div class="modal" id="mdelete" role="dialog" aria-labelledby="moddelete">
    <div class="modal-dialog" role="document">
    <div class="modal-content">
    <div class="modal-header">
    <h5 class="modal-title" id="moddelete">Confirm Delete</h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
    <span aria-hidden="true">&times;</span>
    </button>
    </div>
    <div class="modal-body">
    <p>Are you sure you want to delete</p>
    </div>
    <div class="modal-footer">
    <form method="POST" id="formdelete">
    <input type="hidden" name="txtid" id="txtid" />
    <input type="text" name="uid" id="uid" />
    <button type="button" class="btn btn-danger " data-dismiss="modal">No</button>
    <span class="text-right">
    <button type="submit" class="btn btn-primary btndelete">Yes</button>
    </span>
    </form>
    </div>
    </div>
    <a href=" route('users.show', $user->id) " class="btn btn-primary mr-2">Show</a>
    <a href=" route('users.edit', $user->id) " class="btn btn-info text-white mx-2">Edit</a>
    <button type="button" class="btn btn-danger ml-2" data-toggle="modal"
    data-target="#mdelete" data-id="$user->id"
    data-name="$user->username">Delete</button>

    $(document).ready(function()
    $('#mdelete').on('show.bs.modal', function (event)
    var button = $(event.relatedTarget);
    var userid = button.data('id');
    var uname = button.data('name');
    var modal = $(this);
    modal.find('#txtid').val(userid);
    modal.find('#uid').val(userid);
    modal.find('.modal-body').text('Are you sure you want to delete ' + uname);
    )
    $('#formdelete').submit(function()
    var userid = $('#txtid').val();
    $('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");
    $('#formdelete').submit();
    );
    );









    share|improve this question


























      0












      0








      0








      I have a modal with a hidden field of my current id that I need.



      I need to click a button in my modal to confirm if I should delete a user. I setup a form not sure if this is the best option and in javascript set the attr of form to the route but the route isn’t finding the correct path although in the URL it says it correctly what am I missing maybe the route should be in PHP instead of JS?



      <div class="modal" id="mdelete" role="dialog" aria-labelledby="moddelete">
      <div class="modal-dialog" role="document">
      <div class="modal-content">
      <div class="modal-header">
      <h5 class="modal-title" id="moddelete">Confirm Delete</h5>
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
      </button>
      </div>
      <div class="modal-body">
      <p>Are you sure you want to delete</p>
      </div>
      <div class="modal-footer">
      <form method="POST" id="formdelete">
      <input type="hidden" name="txtid" id="txtid" />
      <input type="text" name="uid" id="uid" />
      <button type="button" class="btn btn-danger " data-dismiss="modal">No</button>
      <span class="text-right">
      <button type="submit" class="btn btn-primary btndelete">Yes</button>
      </span>
      </form>
      </div>
      </div>
      <a href=" route('users.show', $user->id) " class="btn btn-primary mr-2">Show</a>
      <a href=" route('users.edit', $user->id) " class="btn btn-info text-white mx-2">Edit</a>
      <button type="button" class="btn btn-danger ml-2" data-toggle="modal"
      data-target="#mdelete" data-id="$user->id"
      data-name="$user->username">Delete</button>

      $(document).ready(function()
      $('#mdelete').on('show.bs.modal', function (event)
      var button = $(event.relatedTarget);
      var userid = button.data('id');
      var uname = button.data('name');
      var modal = $(this);
      modal.find('#txtid').val(userid);
      modal.find('#uid').val(userid);
      modal.find('.modal-body').text('Are you sure you want to delete ' + uname);
      )
      $('#formdelete').submit(function()
      var userid = $('#txtid').val();
      $('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");
      $('#formdelete').submit();
      );
      );









      share|improve this question
















      I have a modal with a hidden field of my current id that I need.



      I need to click a button in my modal to confirm if I should delete a user. I setup a form not sure if this is the best option and in javascript set the attr of form to the route but the route isn’t finding the correct path although in the URL it says it correctly what am I missing maybe the route should be in PHP instead of JS?



      <div class="modal" id="mdelete" role="dialog" aria-labelledby="moddelete">
      <div class="modal-dialog" role="document">
      <div class="modal-content">
      <div class="modal-header">
      <h5 class="modal-title" id="moddelete">Confirm Delete</h5>
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
      </button>
      </div>
      <div class="modal-body">
      <p>Are you sure you want to delete</p>
      </div>
      <div class="modal-footer">
      <form method="POST" id="formdelete">
      <input type="hidden" name="txtid" id="txtid" />
      <input type="text" name="uid" id="uid" />
      <button type="button" class="btn btn-danger " data-dismiss="modal">No</button>
      <span class="text-right">
      <button type="submit" class="btn btn-primary btndelete">Yes</button>
      </span>
      </form>
      </div>
      </div>
      <a href=" route('users.show', $user->id) " class="btn btn-primary mr-2">Show</a>
      <a href=" route('users.edit', $user->id) " class="btn btn-info text-white mx-2">Edit</a>
      <button type="button" class="btn btn-danger ml-2" data-toggle="modal"
      data-target="#mdelete" data-id="$user->id"
      data-name="$user->username">Delete</button>

      $(document).ready(function()
      $('#mdelete').on('show.bs.modal', function (event)
      var button = $(event.relatedTarget);
      var userid = button.data('id');
      var uname = button.data('name');
      var modal = $(this);
      modal.find('#txtid').val(userid);
      modal.find('#uid').val(userid);
      modal.find('.modal-body').text('Are you sure you want to delete ' + uname);
      )
      $('#formdelete').submit(function()
      var userid = $('#txtid').val();
      $('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");
      $('#formdelete').submit();
      );
      );






      javascript php laravel bootstrap-4






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 at 4:21









      Udhav Sarvaiya

      2,52392131




      2,52392131










      asked Mar 9 at 3:14









      BigbearBigbear

      2910




      2910






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Your attempt to generate route will fail because you are not using templating correctly:



          $('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");



          You can try to have your route accept optional user field, and then generate route to it, and with js append user ID value something like so:



          <script>
          $(function()
          var form = $('#formdelete');
          var path = ' route("users.destroy") ';

          $('#formdelete').submit(function(event)
          var form = $(this);
          var userid = form.find('#txtid').val();
          $('#formdelete').attr("action", path + '/' + userid);
          $('#formdelete').submit();
          );
          );
          </script>





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073645%2flaravel-modal-hidden-value-to-call-route%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Your attempt to generate route will fail because you are not using templating correctly:



            $('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");



            You can try to have your route accept optional user field, and then generate route to it, and with js append user ID value something like so:



            <script>
            $(function()
            var form = $('#formdelete');
            var path = ' route("users.destroy") ';

            $('#formdelete').submit(function(event)
            var form = $(this);
            var userid = form.find('#txtid').val();
            $('#formdelete').attr("action", path + '/' + userid);
            $('#formdelete').submit();
            );
            );
            </script>





            share|improve this answer



























              0














              Your attempt to generate route will fail because you are not using templating correctly:



              $('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");



              You can try to have your route accept optional user field, and then generate route to it, and with js append user ID value something like so:



              <script>
              $(function()
              var form = $('#formdelete');
              var path = ' route("users.destroy") ';

              $('#formdelete').submit(function(event)
              var form = $(this);
              var userid = form.find('#txtid').val();
              $('#formdelete').attr("action", path + '/' + userid);
              $('#formdelete').submit();
              );
              );
              </script>





              share|improve this answer

























                0












                0








                0







                Your attempt to generate route will fail because you are not using templating correctly:



                $('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");



                You can try to have your route accept optional user field, and then generate route to it, and with js append user ID value something like so:



                <script>
                $(function()
                var form = $('#formdelete');
                var path = ' route("users.destroy") ';

                $('#formdelete').submit(function(event)
                var form = $(this);
                var userid = form.find('#txtid').val();
                $('#formdelete').attr("action", path + '/' + userid);
                $('#formdelete').submit();
                );
                );
                </script>





                share|improve this answer













                Your attempt to generate route will fail because you are not using templating correctly:



                $('#formdelete').attr("action", "route('$users.destroy',$user->"+ userid +")");



                You can try to have your route accept optional user field, and then generate route to it, and with js append user ID value something like so:



                <script>
                $(function()
                var form = $('#formdelete');
                var path = ' route("users.destroy") ';

                $('#formdelete').submit(function(event)
                var form = $(this);
                var userid = form.find('#txtid').val();
                $('#formdelete').attr("action", path + '/' + userid);
                $('#formdelete').submit();
                );
                );
                </script>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 9 at 3:31









                HelpNeederHelpNeeder

                3,2212067130




                3,2212067130





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073645%2flaravel-modal-hidden-value-to-call-route%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                    List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229