Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6850999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:11:38+00:00 2026-05-27T01:11:38+00:00

I’m creating a wall that, should look and act like Facebook’s wall. The problem

  • 0

I’m creating a wall that, should look and act like Facebook’s wall. The problem I’m facing is, that I would like to make it able to comment on posts. But I can’t seem to figure out, how to make a comment form appear (a input field with type=text) to the posts.

So I have a block of code to print out all posts and the following comments from the database to the site through a while loop. But I don’t know how to make it print a line with a button to create a input form onclick.

The code is below, first the Danish-English translation:

  • beskeder = the table in my MySQL database containing the posts
  • kommentarer = the table in my MySQL database containing comments to the posts
  • navn = name
  • besked = message
  • kommentar = comment

The JSP code:

<%
    if (wallrs != null) {
        while(wallrs.next()) {
%>
            <br><b><%=wallrs.getString("navn")%></b>
            <br><%=wallrs.getString("besked") %>
<%
            int wallrsid = wallrs.getInt("id");
            dbconnect.getKommentarResultset(wallrsid);
            ResultSet kommentarrs = dbconnect.getKommentarRS();

            if (kommentarrs != null) {
                while (kommentarrs.next()) {
%>
                    <Blockquote>
                        <b><%=kommentarrs.getString("navn") %>:</b>
                        <br><%=kommentarrs.getString("kommentar") %>
                    </Blockquote>
<%
                }
            }
%>
            <form id="besked<%= wallrsid%>"></form>
            <button type="submit" onclick="show_form()">Kommenter</button>
<%
        }
    }
%>

The JavaScript function it’s linking to:

function show_form() {
    document.getElementById("besked").innerHTML = "<input type=text value=Skriv>";
}

The JavaBean:

public void createMessage(String besked, String ip) {
    try {
        PreparedStatement pstmcreateMessage = con.prepareStatement("INSERT INTO beskeder(navn, besked, ip) VALUES(?,?,?)");
        pstmcreateMessage.setString(1, getName());
        pstmcreateMessage.setString(2, besked);
        pstmcreateMessage.setString(3, ip);
        pstmcreateMessage.executeUpdate();
        System.out.println("SUCCES! ");
    } catch(Exception e) {
        e.printStackTrace();
        System.out.println("Can't create message");
    }
}

public void createComment(String kommentar, String ip, int beskedid) {
    try {
        PreparedStatement pstmcreateComment = con.prepareStatement("INSERT INTO kommentarer(navn, kommentar, ip, beskedid) VALUES(?,?,?,?)");
        pstmcreateComment.setString(1, getName());
        pstmcreateComment.setString(2, kommentar);
        pstmcreateComment.setString(3, ip);
        pstmcreateComment.setInt(4, beskedid);
    } catch(Exception e) {
        e.printStackTrace();
        System.out.println("Can't create comment");
    }
}

// Returner hele væggen i et result set
private ResultSet wallRS;
public void getWallResultset() {
    PreparedStatement getWall;
    try {
        getWall = con.prepareStatement("SELECT * FROM beskeder");
        wallRS = getWall.executeQuery();
    } catch (SQLException e) {
        System.out.println("Error in resultset wall rs");
        // e.printStackTrace();
    }
}

public ResultSet getWallrs() {
    return wallRS;
}

// Returner kommentarer
private ResultSet kommentarRS;
public void getKommentarResultset(int beskedid) {
    PreparedStatement getComment;
    try {
        getComment = con.prepareStatement("SELECT * FROM kommentarer WHERE beskedid=?");
        getComment.setInt(1, beskedid);
        kommentarRS = getComment.executeQuery();
    } catch(Exception e) {
        e.printStackTrace();
    }
}

public ResultSet getKommentarRS() {
    return kommentarRS;
}

As you see the form with id="besked" isn’t unique, so I can’t make them show individually. How can I solve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:11:38+00:00Added an answer on May 27, 2026 at 1:11 am

    You’d need to pass the form ID to the JS function so that it can locate the right form.

    Replace

    <button type="submit" onclick="show_form()">Kommenter</button>
    

    by

    <button onclick="show_form('besked<%= wallrsid%>')">Kommenter</button>
    

    and replace

    function show_form() {
        document.getElementById("besked").innerHTML = "<input type=text value=Skriv>";
    }
    

    by

    function show_form(id) {
        document.getElementById(id).innerHTML = '<input type="text" name="kommentar" value="Skriv">';
    }
    

    Unrelated to the concrete problem, scriptlets are considered poor practice and your JDBC code is leaking DB resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.