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?

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.