Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I can't write data in document.write coming from database.

    a dynamically data is coming from database(saved using text area) e.g
    aaaaaaaaaa
    bbbbbbbb
    ccccccc

    when i try it to write in document,.write it generates some ambiguous error?
    <script type=text/javascript>
    document.write("<p>
    aaaaaaaa
    bbbbb
    </p>)";
    </script>

    but when i try to write it as
    <script type=text/javascript>document.write("<p>aaaaaaaa bbbbb</p>");</script>

    what could be problem and its solution please help me out.

    thanks in advance.

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,707
    Thanks
    0
    Thanked 237 Times in 232 Posts
    Hi there naeembhatti,

    try it like this...
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    document.write('<p>'+
    'aaaaaaaa<br\/>'+
    'bbbbb'+
    '<\/p>');
    </script>
    
    </head>
    <body>
    
    <div></div>
    
    </body>
    </html>
    
    coothead

  • #3
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,707
    Thanks
    0
    Thanked 237 Times in 232 Posts
    Hi there naeembhatti,

    as document.write() usage should be avoided...

    Assistive technologies such as screen readers rely on the Document Object Model (DOM) to interpret the semantics in HTML for a different modality.
    Given this, the document.write() and innerHTML() methods can render content invalid (and inaccessible via DOM) after the fact.
    Source:-
    ...I thought that you might be interested in this method...
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    
     var letters=new Array();
         letters[0]='aaaaaaaa';
         letters[1]='bbbbb';
         letters[2]='ccccccc';
    
     var elem=new Array();
     var text=new Array();
    
    window.onload=function(){
    for(c=0;c<letters.length;c++) {
       elem[c]=document.createElement('div');
       text[c]=document.createTextNode(letters[c]);
       elem[c].appendChild(text[c]);
       document.getElementById('mydiv').appendChild(elem[c]);
      }
     }
    </script>
    
    </head>
    <body>
    
    <div id="mydiv"></div>
    
    </body>
    </html>
    
    coothead

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh great my problem solved thanks so much coothead.

  • #5
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,707
    Thanks
    0
    Thanked 237 Times in 232 Posts
    No problem, you're welcome.


  •  

    Posting Permissions

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