WEB AJAX/DOM noob question....

Discussion in 'OT Technology' started by jdw, Mar 23, 2008.

  1. jdw

    jdw New Member

    Joined:
    Dec 31, 2005
    Messages:
    4,429
    Likes Received:
    0
    Location:
    ND
    I'm working on this little project and I've hit a wall. I think I realize the 'right' way to have done it, but none the less it's left me with a question.

    Say you have AJAX load a block of content inside a DIV and part of that content is a text area.
    Can you then access the value in that text area somehow?



    It's basically the same type of functionality forums(vbb and the like) have for editing posts but it's for something personal on the back end of my site (and something to play with learning AJAX). I've got a query hitting the DB and returning blocks of content. I want to edit content in 'x' div so I was replacing the content of 'x' div with the results of editpost.php which shows a text area and save button.

    document.getElementById(x).getElementsByTagName("textarea").value is undefined....




    I think in reading a tutorial here... I need to be doing the majority of it in Javascript and just use 'AJAX' to send the information to the Database...
     
  2. Vailripper

    Vailripper Daywalkers have feelings too.

    Joined:
    Jan 25, 2006
    Messages:
    6,170
    Likes Received:
    0
    Location:
    Bellingham, WA
    AJAX is simply javascript using the xml object. All you need to do is pull the value out of the textarea, then use a standard AJAX script to send it to your server side script which does the database work.
     
  3. jdw

    jdw New Member

    Joined:
    Dec 31, 2005
    Messages:
    4,429
    Likes Received:
    0
    Location:
    ND
    I know as much...

    But I'm having trouble accessing the value said textarea...
     
  4. Vailripper

    Vailripper Daywalkers have feelings too.

    Joined:
    Jan 25, 2006
    Messages:
    6,170
    Likes Received:
    0
    Location:
    Bellingham, WA
    document.getElementById('myText').value

    Where myText = the ID of the textbox.

    Then you can build a link to your php page with the text appended as a variable/value pair, then your PHP page pulls that value.
     
  5. jdw

    jdw New Member

    Joined:
    Dec 31, 2005
    Messages:
    4,429
    Likes Received:
    0
    Location:
    ND

    well I guess I can try giving the textarea an ID and go that route, but as I said in my first post document.getElementById(x).getElementsByTagName("t extarea").value is undefined.... which should be returning the value the same way as hitting the textarea via ID.
     
  6. fishbulb

    fishbulb Active Member

    Joined:
    Oct 29, 2001
    Messages:
    6,848
    Likes Received:
    4
    Location:
    md
    .
     
  7. ez4me2c3d

    ez4me2c3d Cold Member

    Joined:
    Sep 19, 2003
    Messages:
    1,836
    Likes Received:
    0
    Location:
    Minneapolis, MN
    That's because getElementsByTagName returns an array.

    Try this:
    Code:
    document.getElementById(x).getElementsByTagName("textarea").item(0).value;
    Or this, which is the same thing:
    Code:
    document.getElementById(x).getElementsByTagName("textarea")[0].value;
     
  8. jdw

    jdw New Member

    Joined:
    Dec 31, 2005
    Messages:
    4,429
    Likes Received:
    0
    Location:
    ND

    :bowdown:

    that's what I was fucking up...
     

Share This Page