In your example the textarea and the input tags are both invalid. The textarea has no closing tag and the input tag is malformed, no closing '>'. Try this:
HTML Code:
<form name="news" method="post" action="">
<textarea name="msg" cols="60" rows="15" id="msg">Hey</textarea>
<input type="button" name="b1" id="b1" value=" U " onclick="alert(this.form.elements[0].value)">
</form>
This depends upon the textarea being the first element in the form, if your function looks like so or has similar language:
Code:
<script type="text/javascript">
function alertArea(form){
for (var i_tem = 0; i_tem < form.elements.length; i_tem++)
if (form.elements[i_tem].tagName.toLowerCase()=='textarea'){
alert (form.elements[i_tem].value)
break;
}
}
</script>
It will find the first textarea in the form. Your markup could be like so:
HTML Code:
<form name="news" method="post" action="">
<textarea name="msg" cols="60" rows="15" id="msg">Hey</textarea>
<input type="button" name="b1" id="b1" value=" U " onclick="alertArea(this.form)">
</form>
Bookmarks