Need help in JAVASCRIPT

Discussion in 'JavaScript' started by shotazi, Nov 20, 2007.

  1. #1
    Hello everyone!
    I'm newbie here and need some help. Could anyone help with javascript? I have two <textarea> tegs that chenges dynamically... When we enter something in first field, automaticaly changes second. But I have some problems with that:
    When I go to second line of first field second filed does not follow... I need second field to move with first and when someone enters something in the first field, to change second too...
     
    shotazi, Nov 20, 2007 IP
  2. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you mean that every keypress in the first window triggers the second to update, or just when they enter something and click a button?

    Can you post the relevant portions of the code?
     
    James McMurray, Nov 20, 2007 IP
  3. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you could probably just use

    onkeyup="document.getElementById('second_text_area').innerHTML = this.innerHTML"

    however this may have some performance issues for longer texts

    **** Decided to make a test page for this and found out my solution doesn't work at all....probably the same thing you already had
     
    Jamie18, Nov 20, 2007 IP
  4. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That works if you use .value instead.

    <textarea height=5 width=50 onkeyup="document.getElementById('second_text_area').value = this.value"></textarea>
    <textarea height=5 width=50 id="second_text_area"></textarea>
    Code (markup):
    It's really choppy, though.
     
    James McMurray, Nov 20, 2007 IP
  5. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No, I don't mean each character, I mean each line....
    I've got some hash function...
    And want to hash every line in the first <textarea> tag... When we enter something in the first line of firsst textarea to hash it and we move to second line we want live second textarea's first line hashed and go to second line an hash again...
     
    shotazi, Nov 22, 2007 IP
  6. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    alright.. so whenever the user hits enter you want the second textarea updated?

    so just check for the enter key before the update happens..

    
    <textarea height=5 width=50 onkeyup="if(isEnter(event)){document.getElementById('second_text_area').value = this.value}"></textarea>
    <textarea height=5 width=50 id="second_text_area"></textarea>
    <script type="text/javascript">
      function isEnter(evt) {
        evt = (evt) ? evt : event;
        var charCode = (evt.charCode) ? evt.charCode :
            ((evt.which) ? evt.which : evt.keyCode);
        if (charCode == 13) {
            return true;
        } else {
            return false;
        }
      }
    </script>
    Code (markup):
     
    Jamie18, Nov 22, 2007 IP