Jump to content

Getting the content of a textarea after changing it


Vigilant Psyche

Recommended Posts

Say I have

 

<textarea class='field' id='edit_t' rows=5 cols=30>foo</textarea>

 

then I type in the text area, changing the value from "foo" to "bar", then I use this script:

 

var new_text=document.getElementById('edit_t').innerHTML;

alert(new_text);

 

It still shows foo and not the new value of "bar". How can I fix this please guys?

Link to comment
Share on other sites

Can you show us the context of your function calls? This works just fine for me:

<script type="text/javascript">
function getValue(ele)
{
  var e = document.getElementById(ele);
  alert('Current value: ' + e.value);
}
</script>

<textarea id="myText" cols="40" rows="8" name="myText">foo</textarea><br />
<a href="#" onclick="getValue('myText'); return false;">Get Value</a>

 

Tested in both FF and IE

Link to comment
Share on other sites

The script is run here when you click "edit".

 



function open_edit(id)
{
	var div=document.getElementById('edit_div');
	var textarea=document.getElementById('edit_t');
	var center=document.getElementById('edit_center_div');

	textarea.innerHTML="Roorts";
	div.style.display='';

	center.innerHTML="<a href=javascript:edit("+id+")>edit</a>"

}

function edit(id)
{

object();

var div=document.getElementById('edit_div');
var new_text=document.getElementById('edit_t').innerHTML;

alert(new_text);

	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{
			div.style.display='';
		}
	}
	xmlHttp.open("GET",'info.php?body=edit&id='+id+'&new='+new_text,true);
	xmlHttp.send(null);
}




<div style="position:fixed;left:10px;top:10px;display:none;padding:5px;" class='sub_head' id='edit_div'><textarea class='field' id='edit_t' rows=5 cols=30></textarea><br/><div id='edit_center_div' style='text-align:center;'>edit</div></div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.