javascript Whats wrong with this code

user2949525

my textarea and all its atributes is correct, but my javascript not right cannot set value of oTextbox3.

<html>
  <head>
    <title>Retrieving a Textbox Value Example</title>
  </head>
  <body> 
    <textarea rows="5" cols="25" name="txt2"></textarea> <br /> <textarea rows="5"  cols="25" name="txt3"></textarea>
    <br />
    <input type="button" value="Set Values" onclick="setValues()" />

    <script type="text/javascript">
      function setValues() { 
      var oTextbox2= document.getElementById("txt2");
      oTextbox2 = oTextbox2.value; oTextbox2 = oTextbox2.split(" ");
      oTextbox2 = oTextbox2.sort();

      var oTextbox3 = document.getElementById("txt3"); 
      oTextbox3.value = oTextbox2;
      } 
    </script>

  </body>
</html>
Paul Draper

Did you mean oTextbox3.value = oTextbox2.value?

And if you're using getElementById, then you need to use id, not name.

EDIT: Or use document.getElementsByName:

var oTextbox2 = document.getElementsByName('txt2')[0];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related