Laravel - Dependent Dynamic buttons and Sub Dynamic buttons using AJAX and JQUERY
Second Array "Add Another File Button" Does not work . Hello I want to create a dynamic buttons I am not familiar in ajax or jquery though so please guide me, I already have this dynamic button running, but what I want is to create another dynamic button after I Add another form. so here is my code. See my Image, I cannot add another file button after I add form
Here is an image to show what I want and my problem is
What I have here is the Design of the Form
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<br />
<br />
<div class="form-group">
<form name="add_name" id="add_name">
<div class="table-responsive">
<table class="table table-bordered" id="dynamic_field">
<tr>
<td><input type="text" name="name" class="form-control-file" id="exampleFormControlFile1">
<textarea class="form-control" name="areaName" rows="5" id="comment"></textarea>
<input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"><br>
<!--I Want to add another File Button after clicking this button--> <button type="button" name="addFile" id="addFile" class="btn btn-success">Add Another Form</button>
</td>
<td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
</tr>
</table>
<input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />
</div>
</form>
</div>
</div>
</body>
</html>
Here is the AJAX Code which helps the program to run without refreshing and adding form like a loop
<script>
$(document).ready(function(){
var i=1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td> <input type="text" name="name" class="form-control-file" id="exampleFormControlFile1"> <textarea class="form-control" name="areaName" rows="5" id="comment"></textarea><input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"><button type="button" name="addFile" id="addFile" class="btn btn-success">Add Another Form</button></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
$('#submit').click(function(){
$.ajax({
method:"POST",
data:$('#add_name').serialize(),
success:function(data)
{
alert(data);
$('#add_name')[0].reset();
}
});
});
});
</script>
<script>
$(document).ready(function(){
var i=1;
$('#addFile').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td><input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"></button></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
});
</script>
javascript jquery html arrays ajax
add a comment |
Second Array "Add Another File Button" Does not work . Hello I want to create a dynamic buttons I am not familiar in ajax or jquery though so please guide me, I already have this dynamic button running, but what I want is to create another dynamic button after I Add another form. so here is my code. See my Image, I cannot add another file button after I add form
Here is an image to show what I want and my problem is
What I have here is the Design of the Form
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<br />
<br />
<div class="form-group">
<form name="add_name" id="add_name">
<div class="table-responsive">
<table class="table table-bordered" id="dynamic_field">
<tr>
<td><input type="text" name="name" class="form-control-file" id="exampleFormControlFile1">
<textarea class="form-control" name="areaName" rows="5" id="comment"></textarea>
<input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"><br>
<!--I Want to add another File Button after clicking this button--> <button type="button" name="addFile" id="addFile" class="btn btn-success">Add Another Form</button>
</td>
<td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
</tr>
</table>
<input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />
</div>
</form>
</div>
</div>
</body>
</html>
Here is the AJAX Code which helps the program to run without refreshing and adding form like a loop
<script>
$(document).ready(function(){
var i=1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td> <input type="text" name="name" class="form-control-file" id="exampleFormControlFile1"> <textarea class="form-control" name="areaName" rows="5" id="comment"></textarea><input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"><button type="button" name="addFile" id="addFile" class="btn btn-success">Add Another Form</button></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
$('#submit').click(function(){
$.ajax({
method:"POST",
data:$('#add_name').serialize(),
success:function(data)
{
alert(data);
$('#add_name')[0].reset();
}
});
});
});
</script>
<script>
$(document).ready(function(){
var i=1;
$('#addFile').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td><input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"></button></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
});
</script>
javascript jquery html arrays ajax
add a comment |
Second Array "Add Another File Button" Does not work . Hello I want to create a dynamic buttons I am not familiar in ajax or jquery though so please guide me, I already have this dynamic button running, but what I want is to create another dynamic button after I Add another form. so here is my code. See my Image, I cannot add another file button after I add form
Here is an image to show what I want and my problem is
What I have here is the Design of the Form
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<br />
<br />
<div class="form-group">
<form name="add_name" id="add_name">
<div class="table-responsive">
<table class="table table-bordered" id="dynamic_field">
<tr>
<td><input type="text" name="name" class="form-control-file" id="exampleFormControlFile1">
<textarea class="form-control" name="areaName" rows="5" id="comment"></textarea>
<input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"><br>
<!--I Want to add another File Button after clicking this button--> <button type="button" name="addFile" id="addFile" class="btn btn-success">Add Another Form</button>
</td>
<td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
</tr>
</table>
<input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />
</div>
</form>
</div>
</div>
</body>
</html>
Here is the AJAX Code which helps the program to run without refreshing and adding form like a loop
<script>
$(document).ready(function(){
var i=1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td> <input type="text" name="name" class="form-control-file" id="exampleFormControlFile1"> <textarea class="form-control" name="areaName" rows="5" id="comment"></textarea><input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"><button type="button" name="addFile" id="addFile" class="btn btn-success">Add Another Form</button></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
$('#submit').click(function(){
$.ajax({
method:"POST",
data:$('#add_name').serialize(),
success:function(data)
{
alert(data);
$('#add_name')[0].reset();
}
});
});
});
</script>
<script>
$(document).ready(function(){
var i=1;
$('#addFile').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td><input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"></button></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
});
</script>
javascript jquery html arrays ajax
Second Array "Add Another File Button" Does not work . Hello I want to create a dynamic buttons I am not familiar in ajax or jquery though so please guide me, I already have this dynamic button running, but what I want is to create another dynamic button after I Add another form. so here is my code. See my Image, I cannot add another file button after I add form
Here is an image to show what I want and my problem is
What I have here is the Design of the Form
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<br />
<br />
<div class="form-group">
<form name="add_name" id="add_name">
<div class="table-responsive">
<table class="table table-bordered" id="dynamic_field">
<tr>
<td><input type="text" name="name" class="form-control-file" id="exampleFormControlFile1">
<textarea class="form-control" name="areaName" rows="5" id="comment"></textarea>
<input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"><br>
<!--I Want to add another File Button after clicking this button--> <button type="button" name="addFile" id="addFile" class="btn btn-success">Add Another Form</button>
</td>
<td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
</tr>
</table>
<input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />
</div>
</form>
</div>
</div>
</body>
</html>
Here is the AJAX Code which helps the program to run without refreshing and adding form like a loop
<script>
$(document).ready(function(){
var i=1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td> <input type="text" name="name" class="form-control-file" id="exampleFormControlFile1"> <textarea class="form-control" name="areaName" rows="5" id="comment"></textarea><input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"><button type="button" name="addFile" id="addFile" class="btn btn-success">Add Another Form</button></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
$('#submit').click(function(){
$.ajax({
method:"POST",
data:$('#add_name').serialize(),
success:function(data)
{
alert(data);
$('#add_name')[0].reset();
}
});
});
});
</script>
<script>
$(document).ready(function(){
var i=1;
$('#addFile').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td><input type="file" name="fileName" class="form-control-file" id="exampleFormControlFile1"></button></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
});
</script>
javascript jquery html arrays ajax
javascript jquery html arrays ajax
asked Nov 21 '18 at 2:03
Summer WinterSummer Winter
14710
14710
add a comment |
add a comment |
0
active
oldest
votes
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
});
}
});
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%2f53404330%2flaravel-dependent-dynamic-buttons-and-sub-dynamic-buttons-using-ajax-and-jquer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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%2f53404330%2flaravel-dependent-dynamic-buttons-and-sub-dynamic-buttons-using-ajax-and-jquer%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