I have buttons that are created when reading info from a database. When one of the buttons is clicked, a form is created on the fly. The form creates fine, but the problem I am having is setting the text of the button for the form. I have the following to create the form and set the text:
This is the code that sets the button:
<button class="replybtn" id="replybtn<?php echo $commid; ?>" value="<?php echo $commid; ?>">Reply</button>
And this is the code that creates the form when the button is clicked:
$('.replybtn').click(function (e) {
e.preventDefault();
var btnnum = $(this).val();
let replybtn = "replybtn" + btnnum;
let replyform = "replyform" + btnnum;
var form = $("<form>", {
action: 'http://intranet/generalinfo/communitybb/wp-admin/admin-ajax.php',
method: 'POST',
id: replyform,
class: 'replyform'
});
form.append( $("<textarea>", {
name: 'reply',
class: 'commentbox',
rows: '5',
cols: '150'
}));
form.append($("<button>", {
class: 'replybtn',
id: replybtn
}));
$("#" + replybtn).html = "Reply";
});
EDIT
Added in the code that sets the variables.
2
Answers
Thanks for all the replies. I modified the append to the following and that fixed it. Probably not the best way to do it, but it works.
Try this: