Dimony
Dimony

Reputation: 25

submit can't send data of textarea

Recently I study html and javascript. I know that in html form sends data to server between and .

However, in my case it doesn't.

here is my code

function wReply() {
             if(document.getElementById("repInputContent").value == "")  {
                alert("type anything for reply");
                document.getElementById("repInputContent").focus();
                return;
             }
             document.reply.submit();
        }

this is javascript function that work with input type button.

And this is html form code

<tr id="replyInput">
                    <td colspan="3">
                    <form action="/wReply" accept-charset="utf-8" name="reply" method="post">
                        <input type="hidden" name="num" value="<%=num%>">
                        <input type="hidden" name="writer" value="<%=writer%>">
                        <input type="hidden" name="page" value="<%=page%>">
                        <textarea rows="4" cols="40" id="repInputContent"></textarea>
                    </form>
                    </td>
                    <td><input type="button" value="submit" onclick="wReply()"></td>
            </tr>

I code a table and want to send hidden type datas and textarea data. I think it works but actually server can receive hidden type datas.

What is the problem?

Upvotes: 1

Views: 2099

Answers (2)

Vikrant
Vikrant

Reputation: 5036

Wrap your function wReply(){ ... } is inside body tag instead of head! Then Submit button sends data correctly.
As I have tried it myself;

  1. This JSFiddle doesn't work, because script is in Head of the form.

enter image description here

  1. And This is Wroking Demo, where script function wReply(){ ... } is inside body of the form!

enter image description here

Upvotes: 0

cutmancometh
cutmancometh

Reputation: 1727

Your textarea needs a name.

<textarea rows="4" cols="40" id="repInputContent" name="repInputContent"></textarea>

That'll fix you up.

Upvotes: 1

Related Questions