Send data from an index to a bootstrap modal











up vote
0
down vote

favorite












I'm trying to send data from my index page to a modal.



Here's my code.



Modal



  <div class="modal modal-1 fade bd-example-modal-lg " id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title subtitles" id="exampleModalLongTitle">¿Cómo funciona?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="demo">

<!-- Here's where I want to get data -->
<input data-id="sum">

</div>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal"></button> -->
<button type="button" class="btn btn-secondary" data-dismiss="modal" data-toggle="modal" data-target="#exampleModalCenter2" >Siguiente</button>
</div>
</div>
</div>
</div>


First, my button to show my modal



    <button type="button" data-toggle="modal" data-target="#exampleModalCenter" > Cotizar préstamo </button>


Input data that I want to send to my modal



    <input class="c-slider__loan-sum" id="sum" name="loan_sum" type="hidden" value="NaN">
<input class="c-slider__loan-period" name="loan_period" type="hidden" value="20">


And I've been trying with this jQuery



  $('#exampleModalCenter').on('click','shown.bs.modal', function () {
let a = $(this).data('id');
$(".modal-body #sum").val( a );
$('#myInput').trigger('focus');
})


If someone could help me, I'll be so grateful










share|improve this question




















  • 1




    I'm pretty confused about what you are trying to do. There is no data-id on your modal from what I can see. There's also not an element with the id of loan_sum in the modal body (its empty in fact).
    – Taplar
    Nov 7 at 21:39










  • I have an slider in my index. So, when I click button I want to send the current value of the slider to my modal. I've been correct my code.
    – Enrique Alvarez
    Nov 7 at 21:44










  • You still don't have a data-id on your modal. Are you dynamically setting that on the modal some where?
    – Taplar
    Nov 7 at 21:49












  • Actually I solve it. In my inputs I changed value for data-value, as you said.
    – Enrique Alvarez
    Nov 7 at 21:55















up vote
0
down vote

favorite












I'm trying to send data from my index page to a modal.



Here's my code.



Modal



  <div class="modal modal-1 fade bd-example-modal-lg " id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title subtitles" id="exampleModalLongTitle">¿Cómo funciona?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="demo">

<!-- Here's where I want to get data -->
<input data-id="sum">

</div>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal"></button> -->
<button type="button" class="btn btn-secondary" data-dismiss="modal" data-toggle="modal" data-target="#exampleModalCenter2" >Siguiente</button>
</div>
</div>
</div>
</div>


First, my button to show my modal



    <button type="button" data-toggle="modal" data-target="#exampleModalCenter" > Cotizar préstamo </button>


Input data that I want to send to my modal



    <input class="c-slider__loan-sum" id="sum" name="loan_sum" type="hidden" value="NaN">
<input class="c-slider__loan-period" name="loan_period" type="hidden" value="20">


And I've been trying with this jQuery



  $('#exampleModalCenter').on('click','shown.bs.modal', function () {
let a = $(this).data('id');
$(".modal-body #sum").val( a );
$('#myInput').trigger('focus');
})


If someone could help me, I'll be so grateful










share|improve this question




















  • 1




    I'm pretty confused about what you are trying to do. There is no data-id on your modal from what I can see. There's also not an element with the id of loan_sum in the modal body (its empty in fact).
    – Taplar
    Nov 7 at 21:39










  • I have an slider in my index. So, when I click button I want to send the current value of the slider to my modal. I've been correct my code.
    – Enrique Alvarez
    Nov 7 at 21:44










  • You still don't have a data-id on your modal. Are you dynamically setting that on the modal some where?
    – Taplar
    Nov 7 at 21:49












  • Actually I solve it. In my inputs I changed value for data-value, as you said.
    – Enrique Alvarez
    Nov 7 at 21:55













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to send data from my index page to a modal.



Here's my code.



Modal



  <div class="modal modal-1 fade bd-example-modal-lg " id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title subtitles" id="exampleModalLongTitle">¿Cómo funciona?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="demo">

<!-- Here's where I want to get data -->
<input data-id="sum">

</div>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal"></button> -->
<button type="button" class="btn btn-secondary" data-dismiss="modal" data-toggle="modal" data-target="#exampleModalCenter2" >Siguiente</button>
</div>
</div>
</div>
</div>


First, my button to show my modal



    <button type="button" data-toggle="modal" data-target="#exampleModalCenter" > Cotizar préstamo </button>


Input data that I want to send to my modal



    <input class="c-slider__loan-sum" id="sum" name="loan_sum" type="hidden" value="NaN">
<input class="c-slider__loan-period" name="loan_period" type="hidden" value="20">


And I've been trying with this jQuery



  $('#exampleModalCenter').on('click','shown.bs.modal', function () {
let a = $(this).data('id');
$(".modal-body #sum").val( a );
$('#myInput').trigger('focus');
})


If someone could help me, I'll be so grateful










share|improve this question















I'm trying to send data from my index page to a modal.



Here's my code.



Modal



  <div class="modal modal-1 fade bd-example-modal-lg " id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title subtitles" id="exampleModalLongTitle">¿Cómo funciona?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="demo">

<!-- Here's where I want to get data -->
<input data-id="sum">

</div>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal"></button> -->
<button type="button" class="btn btn-secondary" data-dismiss="modal" data-toggle="modal" data-target="#exampleModalCenter2" >Siguiente</button>
</div>
</div>
</div>
</div>


First, my button to show my modal



    <button type="button" data-toggle="modal" data-target="#exampleModalCenter" > Cotizar préstamo </button>


Input data that I want to send to my modal



    <input class="c-slider__loan-sum" id="sum" name="loan_sum" type="hidden" value="NaN">
<input class="c-slider__loan-period" name="loan_period" type="hidden" value="20">


And I've been trying with this jQuery



  $('#exampleModalCenter').on('click','shown.bs.modal', function () {
let a = $(this).data('id');
$(".modal-body #sum").val( a );
$('#myInput').trigger('focus');
})


If someone could help me, I'll be so grateful







javascript jquery html bootstrap-4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 21:41

























asked Nov 7 at 21:36









Enrique Alvarez

114




114








  • 1




    I'm pretty confused about what you are trying to do. There is no data-id on your modal from what I can see. There's also not an element with the id of loan_sum in the modal body (its empty in fact).
    – Taplar
    Nov 7 at 21:39










  • I have an slider in my index. So, when I click button I want to send the current value of the slider to my modal. I've been correct my code.
    – Enrique Alvarez
    Nov 7 at 21:44










  • You still don't have a data-id on your modal. Are you dynamically setting that on the modal some where?
    – Taplar
    Nov 7 at 21:49












  • Actually I solve it. In my inputs I changed value for data-value, as you said.
    – Enrique Alvarez
    Nov 7 at 21:55














  • 1




    I'm pretty confused about what you are trying to do. There is no data-id on your modal from what I can see. There's also not an element with the id of loan_sum in the modal body (its empty in fact).
    – Taplar
    Nov 7 at 21:39










  • I have an slider in my index. So, when I click button I want to send the current value of the slider to my modal. I've been correct my code.
    – Enrique Alvarez
    Nov 7 at 21:44










  • You still don't have a data-id on your modal. Are you dynamically setting that on the modal some where?
    – Taplar
    Nov 7 at 21:49












  • Actually I solve it. In my inputs I changed value for data-value, as you said.
    – Enrique Alvarez
    Nov 7 at 21:55








1




1




I'm pretty confused about what you are trying to do. There is no data-id on your modal from what I can see. There's also not an element with the id of loan_sum in the modal body (its empty in fact).
– Taplar
Nov 7 at 21:39




I'm pretty confused about what you are trying to do. There is no data-id on your modal from what I can see. There's also not an element with the id of loan_sum in the modal body (its empty in fact).
– Taplar
Nov 7 at 21:39












I have an slider in my index. So, when I click button I want to send the current value of the slider to my modal. I've been correct my code.
– Enrique Alvarez
Nov 7 at 21:44




I have an slider in my index. So, when I click button I want to send the current value of the slider to my modal. I've been correct my code.
– Enrique Alvarez
Nov 7 at 21:44












You still don't have a data-id on your modal. Are you dynamically setting that on the modal some where?
– Taplar
Nov 7 at 21:49






You still don't have a data-id on your modal. Are you dynamically setting that on the modal some where?
– Taplar
Nov 7 at 21:49














Actually I solve it. In my inputs I changed value for data-value, as you said.
– Enrique Alvarez
Nov 7 at 21:55




Actually I solve it. In my inputs I changed value for data-value, as you said.
– Enrique Alvarez
Nov 7 at 21:55












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I believe your argument list for .on() is incorrect. If you want to specify multiple events to trigger the handler you separate them with a comma: .on('click, shown.bs.modal', func...).



However, I think you need to remove shown.bs.modal all together, as that event is triggered after the modal has rendered.



Another issue you may have is that you're not actually getting the values from your hidden inputs in your handler. You're just, seemingly, trying to get the id of the button that's being clicked and setting that as the value on some non-existent input in your modal. If you are trying to get the id of the button (for some reason I can't see) then you can get it like this const id = $('#buttonId').attr('id');. What you're doing is trying to get the value from a data attribute that doesn't exist on the button element: ...').data('id');.



Check out this simple example to see how you may want to handle this: https://codepen.io/dustinoverby/pen/NExXMb?editors=1010






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',
    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%2f53198196%2fsend-data-from-an-index-to-a-bootstrap-modal%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








    up vote
    0
    down vote













    I believe your argument list for .on() is incorrect. If you want to specify multiple events to trigger the handler you separate them with a comma: .on('click, shown.bs.modal', func...).



    However, I think you need to remove shown.bs.modal all together, as that event is triggered after the modal has rendered.



    Another issue you may have is that you're not actually getting the values from your hidden inputs in your handler. You're just, seemingly, trying to get the id of the button that's being clicked and setting that as the value on some non-existent input in your modal. If you are trying to get the id of the button (for some reason I can't see) then you can get it like this const id = $('#buttonId').attr('id');. What you're doing is trying to get the value from a data attribute that doesn't exist on the button element: ...').data('id');.



    Check out this simple example to see how you may want to handle this: https://codepen.io/dustinoverby/pen/NExXMb?editors=1010






    share|improve this answer

























      up vote
      0
      down vote













      I believe your argument list for .on() is incorrect. If you want to specify multiple events to trigger the handler you separate them with a comma: .on('click, shown.bs.modal', func...).



      However, I think you need to remove shown.bs.modal all together, as that event is triggered after the modal has rendered.



      Another issue you may have is that you're not actually getting the values from your hidden inputs in your handler. You're just, seemingly, trying to get the id of the button that's being clicked and setting that as the value on some non-existent input in your modal. If you are trying to get the id of the button (for some reason I can't see) then you can get it like this const id = $('#buttonId').attr('id');. What you're doing is trying to get the value from a data attribute that doesn't exist on the button element: ...').data('id');.



      Check out this simple example to see how you may want to handle this: https://codepen.io/dustinoverby/pen/NExXMb?editors=1010






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I believe your argument list for .on() is incorrect. If you want to specify multiple events to trigger the handler you separate them with a comma: .on('click, shown.bs.modal', func...).



        However, I think you need to remove shown.bs.modal all together, as that event is triggered after the modal has rendered.



        Another issue you may have is that you're not actually getting the values from your hidden inputs in your handler. You're just, seemingly, trying to get the id of the button that's being clicked and setting that as the value on some non-existent input in your modal. If you are trying to get the id of the button (for some reason I can't see) then you can get it like this const id = $('#buttonId').attr('id');. What you're doing is trying to get the value from a data attribute that doesn't exist on the button element: ...').data('id');.



        Check out this simple example to see how you may want to handle this: https://codepen.io/dustinoverby/pen/NExXMb?editors=1010






        share|improve this answer












        I believe your argument list for .on() is incorrect. If you want to specify multiple events to trigger the handler you separate them with a comma: .on('click, shown.bs.modal', func...).



        However, I think you need to remove shown.bs.modal all together, as that event is triggered after the modal has rendered.



        Another issue you may have is that you're not actually getting the values from your hidden inputs in your handler. You're just, seemingly, trying to get the id of the button that's being clicked and setting that as the value on some non-existent input in your modal. If you are trying to get the id of the button (for some reason I can't see) then you can get it like this const id = $('#buttonId').attr('id');. What you're doing is trying to get the value from a data attribute that doesn't exist on the button element: ...').data('id');.



        Check out this simple example to see how you may want to handle this: https://codepen.io/dustinoverby/pen/NExXMb?editors=1010







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 22:16









        shaneOverby

        103




        103






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53198196%2fsend-data-from-an-index-to-a-bootstrap-modal%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







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()