Results 1 to 9 of 9

Thread: Dynamic Ajax Content to fill a textarea

  1. #1
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Ajax Content to fill a textarea

    Script: Dynamic Ajax Content
    http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    Is there a way to let the script fill a textarea, instead of a general "rightcolumn" div?

    I plan to use this most useful script to retrieve text from a knowledgebase and send emails.
    For this reason I need the contents to be inserted into a textarea.

    Thank you
    Luigi

    P.S. Yes, I just plan to use plain text, so I would not bother about images and formatting.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    All other things being equal, that is assuming that you can retrieve the content you desire, this is where the contents of the external page are actually written to the 'top' page:

    Code:
    function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
    }
    Specifically, the red line. Now, you can give your textarea an id and access it in that same manner as a division but, a textarea doesn't have an innerHTML object, or if it does, it isn't the same type of thing. What a textarea does have is its value attribute which represents/holds/'stands for' the text it contains. So, you could do this:

    Code:
    document.getElementById(containerid).value=page_request.responseText
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Excellent!
    It does work, smooth and fine.
    Thank you.

    The only issue (one I did not foresee, ignorant as I am) is that now the whole html page is loaded into the textarea, and not just the text as it was originally.

    Is there any way, please, to strip all away, and keep just the real content?

    Luigi

  4. #4
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Well you can first load the respons into an invisible div and then load the innerText of the div into the textarea.

  5. #5
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    > Well you can first load the respons into an invisible div
    > and then load the innerText of the div into the textarea.

    Please, how that would translate, in practical terms?
    Could you please show an example?

    Here is the page I'm working on http://www.kirpi.it/kirpimail/ajaxcars/index4 (still a rough, of course).
    As you see, I add (instead of just loading) page after page, click by click.
    This will eventually allow to gather text from a wiki knowledgebase, which in turn is online and open to all.

    Luigi

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'd use a regEx replace like so:

    Code:
    document.getElementById(containerid).value=page_request.responseText.replace(/<[^>]*>/g, '');
    This will strip all tags that begin and end like:

    Code:
     < . . . >
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    > I'd use a regEx replace...
    > [which] will strip all tags that begin and end like: < . . . >

    Yes, that would be a 90% solution.
    Just I noticed that at times thing are messed up, as it's not smart with spaces and line breaks.

    Luigi

  8. #8
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Quote Originally Posted by kirpi
    Please, how that would translate, in practical terms?
    Could you please show an example?
    Code:
    function loadpage(page_request, containerid){
        if(page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
        document.getElementById("invisiblediv").innerHTML = page_request.responseText;
        document.getElementById(containerid).value = document.getElementById("invisiblediv").innerText;
    }
    You must have a div with style="display:none" and id="invisiblediv" on your page.

    But using replace() is probably still better.

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by kirpi
    > I'd use a regEx replace...
    > [which] will strip all tags that begin and end like: < . . . >

    Yes, that would be a 90% solution.
    Just I noticed that at times thing are messed up, as it's not smart with spaces and line breaks.

    Luigi
    I'm having trouble understanding how spaces would be a problem, though multiple spaces could be treated a certain way if desired. Line breaks, it depends. Do you mean that it is not picking up tags which span line breaks, or that it isn't inserting line breaks where they existed in the formatted HTML? For the former, add the m switch, for the latter use another replace function first to replace <br> with \n and/or format your HTML that you are replacing so that it relies on <br> tags for all important line breaks and/or has actual line breaks where desired.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •