Dirk
Dirk

Reputation: 6884

JQuery Appending a Comma to my TextArea

I can't seem to figure out this situation.

<textarea id="addinfo" name="addinfo"></textarea>

alert(f.addinfo);

If my input into the textarea is "hello", the alert says "hello,". If there is no input, the alert says ",".

What's going on?

Thanks,
Michael

Upvotes: 1

Views: 1288

Answers (3)

Sander
Sander

Reputation: 13421

I recreated a page like you have it,

except i used the addinfo.value

works fine like this:

<html>
<head>
<title>testing textarea value</title>
    <script src="http://www.google.com/jsapi" type="text/javascript"></script>
    <script type="text/javascript">
        google.load("jquery", "1.3.2");
    </script>
    <script language="javascript">
        function test(){
            alert(f.addinfo.value);
        }   
    </script>
</head>
<body>
    <form id="f" name="f">
        <textarea id="addinfo" name="addinfo"></textarea>
        <a href="javascript:test()">test click</a>
    </form>
</body>
</html>

Upvotes: 2

Cristian Toma
Cristian Toma

Reputation: 5799

I've tried to do the same thing you do, with jQuery included and I don't seem to have this problem. Maybe your problem is that you don't get the DOMElement correctly.

Try document.getElementById('addinfo')

And another problem could be that you don't use addinfo.value you just use addinfo which is a DOMElement not the string from the textarea.

Hope this helps.

Upvotes: 3

Yisroel
Yisroel

Reputation: 8174

looks like you may have two fields named addInfo, and youre getting a comma-delimited list of the values

Upvotes: 4

Related Questions