How to add text to modal on button click
up vote
1
down vote
favorite
I have this modal
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
and I would like to add text in <span id="bankAssessBondId"></span>
when the following button is clicked
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
as I have multiple buttons for this, I'm using an EventListener as follows
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].on("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
but the 'click' button event is not detected. How can I fix this?
javascript ajax twitter-bootstrap
add a comment |
up vote
1
down vote
favorite
I have this modal
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
and I would like to add text in <span id="bankAssessBondId"></span>
when the following button is clicked
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
as I have multiple buttons for this, I'm using an EventListener as follows
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].on("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
but the 'click' button event is not detected. How can I fix this?
javascript ajax twitter-bootstrap
It would be good to have some more details, such as how those buttons are created - for example, if they're dynamically generated or populated from an ajax request then that style of event handler won't work...
– John M
Nov 19 at 11:47
yes, the buttons are created by an ajax request. I have a list of transactions each of which has one of those buttons.
– andrex_jux
Nov 19 at 11:49
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have this modal
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
and I would like to add text in <span id="bankAssessBondId"></span>
when the following button is clicked
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
as I have multiple buttons for this, I'm using an EventListener as follows
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].on("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
but the 'click' button event is not detected. How can I fix this?
javascript ajax twitter-bootstrap
I have this modal
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
and I would like to add text in <span id="bankAssessBondId"></span>
when the following button is clicked
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
as I have multiple buttons for this, I'm using an EventListener as follows
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].on("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
but the 'click' button event is not detected. How can I fix this?
javascript ajax twitter-bootstrap
javascript ajax twitter-bootstrap
asked Nov 19 at 11:35
andrex_jux
154
154
It would be good to have some more details, such as how those buttons are created - for example, if they're dynamically generated or populated from an ajax request then that style of event handler won't work...
– John M
Nov 19 at 11:47
yes, the buttons are created by an ajax request. I have a list of transactions each of which has one of those buttons.
– andrex_jux
Nov 19 at 11:49
add a comment |
It would be good to have some more details, such as how those buttons are created - for example, if they're dynamically generated or populated from an ajax request then that style of event handler won't work...
– John M
Nov 19 at 11:47
yes, the buttons are created by an ajax request. I have a list of transactions each of which has one of those buttons.
– andrex_jux
Nov 19 at 11:49
It would be good to have some more details, such as how those buttons are created - for example, if they're dynamically generated or populated from an ajax request then that style of event handler won't work...
– John M
Nov 19 at 11:47
It would be good to have some more details, such as how those buttons are created - for example, if they're dynamically generated or populated from an ajax request then that style of event handler won't work...
– John M
Nov 19 at 11:47
yes, the buttons are created by an ajax request. I have a list of transactions each of which has one of those buttons.
– andrex_jux
Nov 19 at 11:49
yes, the buttons are created by an ajax request. I have a list of transactions each of which has one of those buttons.
– andrex_jux
Nov 19 at 11:49
add a comment |
4 Answers
4
active
oldest
votes
up vote
0
down vote
accepted
For elements that are dynamically generated you'll need to use the delegated events form of the JQuery on() function:
$('body').on('click', '.btn.btn-success.bank', function() {
$('#bankAssessBondId').append($(this).value)
}
I've used "body" in this case as the parent element, but it could be any element that's a parent of the buttons.
add a comment |
up vote
0
down vote
Your issue looks to be that you are trying to use the jquery on with an element that was discovered not using jquery. The way I see it you have two possible solutions depending on what you are trying to achieve.
1: use the addEventListener
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].addEventListener("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
2: use jquey to select the buttons and use the .on function to apply a click listener to all items returned
var buttons = $(".btn.btn-success.bank");
buttons.on("click", () => {
//do stuff here
});
I hope this helps!
add a comment |
up vote
0
down vote
When selecting an element with multiple classes then the selectors must be specified without spaces like below.
$('.btn.bank.btn-success')
Also in this, case the modal should be opened with the script as the span value inside modal needs to be changed dynamically.
$('#bankAssess').modal('toggle');
$(function() {
$('.btn.bank.btn-success').click(function() {
var val = $(this).attr("value");
console.log(val);
$('#bankAssessBondId').append(val);
$('#bankAssess').modal('toggle');
});
});
#bankAssessBondId {
color: red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond2">
Bank Assess
</button>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
add a comment |
up vote
0
down vote
You can get the button by its class name using
$(".bank").on('click', function () {
alert('clicked');
$('#bankAssessBondId').append($(this).attr('value'));
});
Also append the value of the button to the id="bankAssessBondId"
<span id="bankAssessBondId"></span>
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
Using a sample of your code
Here is a working example.
https://codepen.io/anon/pen/oQGJOm
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
For elements that are dynamically generated you'll need to use the delegated events form of the JQuery on() function:
$('body').on('click', '.btn.btn-success.bank', function() {
$('#bankAssessBondId').append($(this).value)
}
I've used "body" in this case as the parent element, but it could be any element that's a parent of the buttons.
add a comment |
up vote
0
down vote
accepted
For elements that are dynamically generated you'll need to use the delegated events form of the JQuery on() function:
$('body').on('click', '.btn.btn-success.bank', function() {
$('#bankAssessBondId').append($(this).value)
}
I've used "body" in this case as the parent element, but it could be any element that's a parent of the buttons.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
For elements that are dynamically generated you'll need to use the delegated events form of the JQuery on() function:
$('body').on('click', '.btn.btn-success.bank', function() {
$('#bankAssessBondId').append($(this).value)
}
I've used "body" in this case as the parent element, but it could be any element that's a parent of the buttons.
For elements that are dynamically generated you'll need to use the delegated events form of the JQuery on() function:
$('body').on('click', '.btn.btn-success.bank', function() {
$('#bankAssessBondId').append($(this).value)
}
I've used "body" in this case as the parent element, but it could be any element that's a parent of the buttons.
answered Nov 19 at 12:01
John M
1,20321120
1,20321120
add a comment |
add a comment |
up vote
0
down vote
Your issue looks to be that you are trying to use the jquery on with an element that was discovered not using jquery. The way I see it you have two possible solutions depending on what you are trying to achieve.
1: use the addEventListener
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].addEventListener("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
2: use jquey to select the buttons and use the .on function to apply a click listener to all items returned
var buttons = $(".btn.btn-success.bank");
buttons.on("click", () => {
//do stuff here
});
I hope this helps!
add a comment |
up vote
0
down vote
Your issue looks to be that you are trying to use the jquery on with an element that was discovered not using jquery. The way I see it you have two possible solutions depending on what you are trying to achieve.
1: use the addEventListener
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].addEventListener("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
2: use jquey to select the buttons and use the .on function to apply a click listener to all items returned
var buttons = $(".btn.btn-success.bank");
buttons.on("click", () => {
//do stuff here
});
I hope this helps!
add a comment |
up vote
0
down vote
up vote
0
down vote
Your issue looks to be that you are trying to use the jquery on with an element that was discovered not using jquery. The way I see it you have two possible solutions depending on what you are trying to achieve.
1: use the addEventListener
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].addEventListener("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
2: use jquey to select the buttons and use the .on function to apply a click listener to all items returned
var buttons = $(".btn.btn-success.bank");
buttons.on("click", () => {
//do stuff here
});
I hope this helps!
Your issue looks to be that you are trying to use the jquery on with an element that was discovered not using jquery. The way I see it you have two possible solutions depending on what you are trying to achieve.
1: use the addEventListener
var buttons = document.getElementsByClassName('btn btn-success bank');
for(var i=0; i<buttons.length; i++){
buttons[i].addEventListener("click", function(){
$('#bankAssessBondId').append($(this).value)
})
}
2: use jquey to select the buttons and use the .on function to apply a click listener to all items returned
var buttons = $(".btn.btn-success.bank");
buttons.on("click", () => {
//do stuff here
});
I hope this helps!
answered Nov 19 at 11:50
kriddy800
1347
1347
add a comment |
add a comment |
up vote
0
down vote
When selecting an element with multiple classes then the selectors must be specified without spaces like below.
$('.btn.bank.btn-success')
Also in this, case the modal should be opened with the script as the span value inside modal needs to be changed dynamically.
$('#bankAssess').modal('toggle');
$(function() {
$('.btn.bank.btn-success').click(function() {
var val = $(this).attr("value");
console.log(val);
$('#bankAssessBondId').append(val);
$('#bankAssess').modal('toggle');
});
});
#bankAssessBondId {
color: red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond2">
Bank Assess
</button>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
add a comment |
up vote
0
down vote
When selecting an element with multiple classes then the selectors must be specified without spaces like below.
$('.btn.bank.btn-success')
Also in this, case the modal should be opened with the script as the span value inside modal needs to be changed dynamically.
$('#bankAssess').modal('toggle');
$(function() {
$('.btn.bank.btn-success').click(function() {
var val = $(this).attr("value");
console.log(val);
$('#bankAssessBondId').append(val);
$('#bankAssess').modal('toggle');
});
});
#bankAssessBondId {
color: red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond2">
Bank Assess
</button>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
add a comment |
up vote
0
down vote
up vote
0
down vote
When selecting an element with multiple classes then the selectors must be specified without spaces like below.
$('.btn.bank.btn-success')
Also in this, case the modal should be opened with the script as the span value inside modal needs to be changed dynamically.
$('#bankAssess').modal('toggle');
$(function() {
$('.btn.bank.btn-success').click(function() {
var val = $(this).attr("value");
console.log(val);
$('#bankAssessBondId').append(val);
$('#bankAssess').modal('toggle');
});
});
#bankAssessBondId {
color: red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond2">
Bank Assess
</button>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
When selecting an element with multiple classes then the selectors must be specified without spaces like below.
$('.btn.bank.btn-success')
Also in this, case the modal should be opened with the script as the span value inside modal needs to be changed dynamically.
$('#bankAssess').modal('toggle');
$(function() {
$('.btn.bank.btn-success').click(function() {
var val = $(this).attr("value");
console.log(val);
$('#bankAssessBondId').append(val);
$('#bankAssess').modal('toggle');
});
});
#bankAssessBondId {
color: red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond2">
Bank Assess
</button>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
$(function() {
$('.btn.bank.btn-success').click(function() {
var val = $(this).attr("value");
console.log(val);
$('#bankAssessBondId').append(val);
$('#bankAssess').modal('toggle');
});
});
#bankAssessBondId {
color: red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond2">
Bank Assess
</button>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
$(function() {
$('.btn.bank.btn-success').click(function() {
var val = $(this).attr("value");
console.log(val);
$('#bankAssessBondId').append(val);
$('#bankAssess').modal('toggle');
});
});
#bankAssessBondId {
color: red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="modal fade" id="bankAssess" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelBank" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabelBank">Bank Assess <span id="bankAssessBondId"></span></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="credit-scoring">
<label for="credit-scoring" class="form-control-label">Credit Scoring:</label>
<input type="text" class="form-control" id="credit-scoring">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="submit-form-Bank">Submit</button>
</div>
</div>
</div>
</div>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond2">
Bank Assess
</button>
<button class="btn btn-success bank" type="button" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
edited Nov 19 at 12:08
answered Nov 19 at 12:02
mbharanidharan88
4,05332253
4,05332253
add a comment |
add a comment |
up vote
0
down vote
You can get the button by its class name using
$(".bank").on('click', function () {
alert('clicked');
$('#bankAssessBondId').append($(this).attr('value'));
});
Also append the value of the button to the id="bankAssessBondId"
<span id="bankAssessBondId"></span>
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
Using a sample of your code
Here is a working example.
https://codepen.io/anon/pen/oQGJOm
add a comment |
up vote
0
down vote
You can get the button by its class name using
$(".bank").on('click', function () {
alert('clicked');
$('#bankAssessBondId').append($(this).attr('value'));
});
Also append the value of the button to the id="bankAssessBondId"
<span id="bankAssessBondId"></span>
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
Using a sample of your code
Here is a working example.
https://codepen.io/anon/pen/oQGJOm
add a comment |
up vote
0
down vote
up vote
0
down vote
You can get the button by its class name using
$(".bank").on('click', function () {
alert('clicked');
$('#bankAssessBondId').append($(this).attr('value'));
});
Also append the value of the button to the id="bankAssessBondId"
<span id="bankAssessBondId"></span>
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
Using a sample of your code
Here is a working example.
https://codepen.io/anon/pen/oQGJOm
You can get the button by its class name using
$(".bank").on('click', function () {
alert('clicked');
$('#bankAssessBondId').append($(this).attr('value'));
});
Also append the value of the button to the id="bankAssessBondId"
<span id="bankAssessBondId"></span>
<button class="btn btn-success bank" type="button" data-toggle="modal" data-target="#bankAssess" value="bond3">
Bank Assess
</button>
Using a sample of your code
Here is a working example.
https://codepen.io/anon/pen/oQGJOm
answered Nov 19 at 12:09
oOo--STAR--oOo
3381418
3381418
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%2f53373796%2fhow-to-add-text-to-modal-on-button-click%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
It would be good to have some more details, such as how those buttons are created - for example, if they're dynamically generated or populated from an ajax request then that style of event handler won't work...
– John M
Nov 19 at 11:47
yes, the buttons are created by an ajax request. I have a list of transactions each of which has one of those buttons.
– andrex_jux
Nov 19 at 11:49