Question

Hey all. I'm scripting a blogging system for my website. So I have this function:

<script language="javascript" type="text/javascript">  
/* <![CDATA[ */  
function reply(text) {  
    document.replyform.comment.value += text;  
}  
/* ]]> */  
</script>

And this link next to each comment:

<a href="#reply" onclick="reply('@<?php echo $name; ?>'); return false">Reply</a>

And my submit comment form has the name tagged to it:

<a name="reply" id="reply">
<form method="post" action="/path/to/form" name="replyform">
// Etc...
<textarea name="comment" id="comment" rows="5" cols="10" class="f-comment"></textarea>
// Etc...

What I want to achieve is that when a user clicks on "Reply" to a certain comment, not only will it add a "@Name" to the form's textbox, but it'll also jump TO the form (as I have included href="#reply"). However that doesn't seem to work and I'm assuming the javascript onclick overrides it?

When it comes to Javascript, I'm completely clueless! What should I do? Thank you.

Was it helpful?

Solution

I would start by closing the reply anchor, <a name="reply" id="reply"></a> and then removing the return false from the link. Returning false ignores the link (href). Another solution is to figure out the position of the anchor link #reply and scroll there using javascript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top