javaScript中怎样获取textarea中的值

解决方案 »

  1.   

    document.getElementbyId("textArea的id").value
      

  2.   

    document.form1.textAreaName.value 或 window.form1.textAreaName.value
    form1为form名称
    textAreaName为textarea的名称。
      

  3.   

    都不行啊。
    document.form1.textAreaName.value 我试了不行的。
      

  4.   

    document.getElementById("text1").value
    有个字母小写了,你不会直接抄的吧
      

  5.   

    function publish(){
    if(document.getElementById("text1").value==""){
       alert("本评价讨论区不能发表空留言!");
       return false;
    }
      return true;
    }
    用了啊,还是不行呢?
      

  6.   

    晕,text1是你对应的那个文本域的id阿
    <textarea id="xxxx" ...
    text1要和你id的值一样
      

  7.   

    textarea域:<textarea id="text1" name="content" cols="100" rows="20">
    </textarea>
    javascript:
    function publish(){
    if(document.getElementById("text1").value==""){
       alert("本评价讨论区不能发表空留言!");
       return false;
    }
      return true;
    }
    怎样你应该看清楚了吧?请高手解决
      

  8.   

    <html>
    <title>this is a test</title>
    <script lang="javascript">function publish(){
    alert('in');
    alert(document.getElementById("text1").value.length); if(document.getElementById("text1").value==''){   alert("本评价讨论区不能发表空留言!");
       return false;
    }  return true;
    }
    </script>
    <body><FORM NAME="myForm">
    <textarea id="text1" name="content" cols="20" rows="20"></textarea><input name="button2" type="button" value="Show Form Elements"
       onClick="publish()">
    </FORM> The alert dialog box displays the following text:
    </body>
    </html>
    我试了下,可以阿,你报什么错了?
      

  9.   

    实在不行 这也可以
    document.all.text1.value
      

  10.   

    <html>
    <head>
    <script language="javascript">
    function show()
    {
    alert(document.form1.demo.value);
    }
    function show2()
    {
             alert(document.getElementById("demo").value);
    }
    function show3()
    {
             alert(document.forms[0].demo.value);
    }
    </script>
    </head>
    <body>
    <form name="form1">
    <input type=text name=text readonly=readonly value="asfasdf"><br>
    <textarea id="demo" name="demo" cols="15" rows="5">test</textarea>
    <input type=button onclick="show();return true;" value=show1>
    <input type=button onclick="show2();return true;" value=show2>
    <input type=button onclick="show3();return true;" value=show3>
    </form>
    </body>
    </html>
      

  11.   

    看了都急!   试过的!<%@ page contentType="text/html;charset=GBK" %>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.util.*" %>
    <%@ page session="true" %>
    <%
    session.putValue("enter","true");
    %>
    <html>
    <title>新的主题</title>
    <HEAD>
    <script language="JavaScript">
    function checkdata(){ if(document.forms[0].subject.value==""){
       alert("本论坛主题不能为空!");
       return false;
    }
     
    if(document.forms[0].content.value==""){
       alert("本论坛不能发表空留言!");
       return false;
    }
      return true;
    }
    </script>
    </HEAD>
    <body bgcolor="#DEF3CE">
    <%@include file="../inc/session.inc"%> 
    <%@include file="../inc/rq.inc"%> 
    <center>
    <table width="600" border="0" cellspacing="0" bgcolor="#DEF3CE"  bordercolor="white" align="center">
    <tr align="center" bgcolor="#DEF3CE"> 
    <td width=60% align=left><font size=2 color=blue><b>【新的主题】</b></font></td>
    <td width=40% align=left><font size=2 color=red><a href=discuss_brows.jsp><font size=2>回论坛看板</font></a>
    </font></td></tr>
    </table>
    <hr size=1 width=80% color=red>
    <table border=0>
    <form action=savemain.jsp method=post OnSubmit="return checkdata()">
    <tr><td align=left><font size=2>作者[<%=user%>]&nbsp;部门[<%=dep%>]&nbsp;[日期]<%=rq%><%=time%></font></td></tr>
    </table>
    <hr size=1 width=80% color=white>
    <table>
    <input type=hidden size=40 name=bm value=<%=dep%>>
    <input type=hidden size=40 name=name value=<%=user%>>
    </tr>
    <tr><td><font size=2>主题</font></td><td ><input type=text size=60 id=subject name=subject></td></tr>
    <tr><td valign=top ><font size=2>内容</font></td><td><textarea id="content" name="content" rows=10 cols=60></textarea></td></tr>
    </table>
    <table>
    <tr align=center><td calign=center olspan=2><input type=submit name=send value=确定><input type=reset name=reset value=清除></td></tr>
    </table>
    <hr size=1 width=80% color=red>
    </form>
    </body>
    </html>
      

  12.   

    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <script language="JavaScript">
    <!--
    function alertTextareaText() {
    var value=document.form.textarea.value;
    alert(value);
    }
    //-->
    </script>
    </head><body>
    <form method=post action="" name="form">
    <textarea name="textarea" rows="10" cols="60"></textarea>
    <input type="button" value="测试" onclick="alertTextareaText();">
    </form>
    </body>
    </html>
      

  13.   

    <%@ page contentType="text/html;charset=GBK"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.util.*"%>
    <%@ page session="true"%>
    <%session.putValue("enter", "true");
    %>
    <html>
    <title>新的主题</title>
    <HEAD>
    <script language="JavaScript">
    function checkdata(){ if(document.forms[0].subject.value==""){
       alert("本论坛主题不能为空!");
       return false;
    }
     
    if(document.forms[0].content.value==""){
       alert("本论坛不能发表空留言!");
       return false;
    }
      return true;
    }
    </script>
    </HEAD>
    <body bgcolor="#DEF3CE">
    <%@include file="../inc/session.inc"%>
    <%@include file="../inc/rq.inc"%>
    <center>
    <table width="600" border="0" cellspacing="0" bgcolor="#DEF3CE"
    bordercolor="white" align="center">
    <tr align="center" bgcolor="#DEF3CE">
    <td width=60% align=left><font size=2 color=blue><b>【新的主题】</b></font></td>
    <td width=40% align=left><font size=2 color=red><a
    href=discuss_brows.jsp><font size=2>回论坛看板</font></a> </font></td>
    </tr>
    </table>
    <hr size=1 width=80% color=red>
    <form action=savemain.jsp method=post OnSubmit="return checkdata()">
    <table border=0> <tr>
    <td align=left><font size=2>作者[<%=user%>]&nbsp;部门[<%=dep%>]&nbsp;[日期]<%=rq%><%=time%></font></td>
    </tr>
    </table>
    <hr size=1 width=80% color=white>
    <table>
    <input type=hidden size=40 name=bm value=<%=dep%>>
    <input type=hidden size=40 name=name value=<%=user%>>
    </tr>
    <tr>
    <td><font size=2>主题</font></td>
    <td><input type=text size=60 id=subject name=subject></td>
    </tr>
    <tr>
    <td valign=top><font size=2>内容</font></td>
    <td><textarea id="content" name="content" rows=10 cols=60></textarea></td>
    </tr>
    </table>
    <table>
    <tr align=center>
    <td calign=center olspan=2><input type=submit name=send value=确定><input
    type=reset name=reset value=清除></td>
    </tr>
    </table>
    <hr size=1 width=80% color=red>
    </form>
    </body>
    </html>
    这样试下
      

  14.   

    不要用=="",最好是判断value.length==0
      

  15.   

    楼上的错了.
    document.all["textArea的id"].value,这样怎么都可以取到textare中的值了.