javascript - Uncaught ReferenceError: {function ONCLICK} is not defined at HTMLAnchorElement.onclick

I have one pageindex.php
and the other oneinclude/comments.php
.
index.php
<div class="row replybox" style="display:none">
<div class="col-md-12">
<textarea class="form-control" id="rComment" cols="30" rows="2"></textarea><br>
<button style="" class="btn-primary btn" id="addReply">Add Reply</button>
</div>
</div>
<script type="text/javascript">
function reply(x) {
$('.replybox').show();
}
</script>
include/comments.php
function DisplayComment($data){
return '
<div class="comment">
<div class="useremail">'.$data['email'].' <span class="date_time">'.$data['date'].'</span></div>
<div class="comment">'.$data['comment'].'</div>
<div class="reply"><a href="#" onclick="reply(this)">REPLY</a></div>
<div class="replytext"></div>
</div>
';
}
When I click on the reply link, the following error is displayed
ReferenceError: reply is not defined at HTMLAnchorElement.onclick
I am not able to show the div ($('.replybox').show();)... Can someone help me. thank you.
Answer
Solution:
I think it seems like there is an error in the connection. because you have assigned href to the a tag and the onclick event. I will recommend you to try as follows.
<div class="row replybox" id="replybox" style="display:none">
<div class="col-md-12">
<textarea class="form-control" id="rComment" cols="30" rows="2"></textarea><br>
<button style="" class="btn-primary btn" id="addReply">Add Reply</button>
</div>
</div>
function DisplayComment($data){
return '
<div class="comment">
<div class="useremail">'.$data['email'].' <span class="date_time">'.$data['date'].'</span></div>
<div class="comment">'.$data['comment'].'</div>
<div class="reply"><button type="button" onclick="reply()">REPLY</button></div>
<div class="replytext"></div>
</div>
';
}
and please try this
<script type="text/javascript">
function reply() {
document.getElementById('replybox').style.display = "block";
}
</script>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: method illuminate\database\eloquent\collection::paginate does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.