tags:

views:

235

answers:

3

Hi all,
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

+1  A: 

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

Yisroel
I actually think this is what's happening here... When I store a default value to the textarea, say <textarea>Default</textarea>, If I input say, "Hello", I get "Hello,Default"
Michael
then it is because you don't use the addinfo.value and instead you get a list of all properties comma separated.
Sander
But I only have one field named addInfo ...
Michael
can you post more of your page? clearly thats not all the code on the page
Yisroel
I figured it out; it was two fields of the same name... I was using a plugin called Impromptu, and didn't realize I had created two of the same field!Thanks
Michael
+3  A: 

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.

Christian Toma
Thanks, upvoted for the effort.
Michael
+2  A: 

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>
Sander
Thanks, upvoted for the effort, I didn't provide much code to make an accurate diagnosis, turns out to be arnie's answer.
Michael