...

View Full Version : I can't write data in document.write coming from database.



naeembhatti
12-04-2006, 01:58 PM
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.

coothead
12-04-2006, 03:11 PM
Hi there naeembhatti,

try it like this...


<!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

coothead
12-04-2006, 03:41 PM
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:-

http://www.w3.org/TR/2004/WD-WCAG20-SCRIPT-TECHS-20041119/#doc-write
...I thought that you might be interested in this method...


<!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

naeembhatti
12-05-2006, 05:59 AM
oh great my problem solved thanks so much coothead.

coothead
12-05-2006, 08:07 AM
No problem, you're welcome. ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum