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">×</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
add a comment |
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">×</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
1
I'm pretty confused about what you are trying to do. There is nodata-id
on your modal from what I can see. There's also not an element with the id ofloan_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 adata-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 changedvalue
fordata-value
, as you said.
– Enrique Alvarez
Nov 7 at 21:55
add a comment |
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">×</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
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">×</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
javascript jquery html bootstrap-4
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 nodata-id
on your modal from what I can see. There's also not an element with the id ofloan_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 adata-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 changedvalue
fordata-value
, as you said.
– Enrique Alvarez
Nov 7 at 21:55
add a comment |
1
I'm pretty confused about what you are trying to do. There is nodata-id
on your modal from what I can see. There's also not an element with the id ofloan_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 adata-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 changedvalue
fordata-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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 7 at 22:16
shaneOverby
103
103
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 ofloan_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
fordata-value
, as you said.– Enrique Alvarez
Nov 7 at 21:55