views:

41

answers:

1

I need to be able to comment to an article, but also be able to reply to a comment using the same form. Fairly simple, but how do I know that a user clicked on "REPLY", and know which comment they clicked "REPLY" too? I'd imaging I need to add some attribute to the anchor, but I'm not sure what it should be. I'd like this to be a best practice kind of thing.

you have Spring-mvc, JSP, and jQuery at your disposal

these anchors are generated at the bottom of every comment, you have access to any comment info you need from the model at this point: <a href="#" title="Reply"><img src="<spring:url value="/static/images/reply.png"/>" alt="reply" width="10" height="10" border="0" />REPLY</a>

this is the actual form to make a comment:

<form:form action="comment.do" method="PUT">
    <div class="aclass">
        <h2>post a comment</h2>
    </div>
    <input type="hidden" name="replyto" value=""/>
    <input type="text" class="commentArea" name="comment"/>
    <div style="margin: 5px 0 0 0">
        <input type="submit" value="Submit Comment" title="Submit Comment" />
        &nbsp;
    </div>
</form:form>

brownie points for making clicking "reply" scroll the user to the comment form :)

+1  A: 

Store the ID of the comments in each reply button, so when it is clicked you can move that ID to a hidden form field for your comment box. If no ID is present then it is a normal comment and not a reply.

Jeremy
but how do I store the id of the comment in the reply link?
walnutmon
Set the anchor tag to have an ID that is formatted for easy splitting. Like `<a id="reply-123">` Then have a JavaScript function that handles the click event on the reply link that splits the ID by the hyphen. You'll get an array, then send array[1] (which will be 123 in this case) to the hidden form field.
Jeremy