...

View Full Version : XHTML Validation



Alaa
05-12-2009, 09:34 AM
Hi,
I have a error when I validate my wabpage,
the error is
document type does not allow element "li" here

new Insertion.Bottom('groceries', '<li>' + val + '</li>');

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).


my source is :

<body>
<script language= "javascript" type="text/javascript">
function addElementBottom(){
var val = $F('newItemtxt');
new Insertion.Bottom('listOfElements', '<li>' + val + '</li>');
new Field.clear('newItemtxt');
}
</script>

<input type="text" id="newItemtxt"/><input type="button" value="add Bottom" onclick="addElementBottom(); "/>

<ul id="listOfElements">
<li>Bread</li>
</ul>

</body>


could u help me please?

_Aerospace_Eng_
05-12-2009, 09:39 AM
You have three options.
Option 1
Move your javascript without the script tags to a .js file then change your code to look like this

<script src="pathtoyourjsfile.js" type="text/javascript"></script>
Be sure to change the src part.
Option 2
Change your code to look like this

<script type="text/javascript">
<![CDATA[
function addElementBottom(){
var val = $F('newItemtxt');
new Insertion.Bottom('listOfElements', '<li>' + val + '</li>');
new Field.clear('newItemtxt');
}
]]>
</script>
Option 3


<script type="text/javascript">
function addElementBottom(){
var val = $F('newItemtxt');
new Insertion.Bottom('listOfElements', '<li>' + val + '<\/li>');
new Field.clear('newItemtxt');
}
</script>
Note: I didn't use language="javascript" in any of the code in my post because it is deprecated and should not be used anymore. type="text/javascript" is required so use that.

If it still doesn't validate then post the rest of your html.

effpeetee
05-12-2009, 09:40 AM
It would help to have all your code or better still a link to your site.

Frank

Alaa
05-12-2009, 10:17 AM
Thanks,
@Aerospace_Eng the second and third solutions did not work, And I think the first one will do, but I want to know the right way to right JS in XHTML.
@Frank, here is the address of my page
http://alaa.oos.cc/web/prototype/proto/files/a.html

http://validator.w3.org/check?uri=http%3A%2F%2Falaa.oos.cc%2Fweb%2Fprototype%2Fproto%2Ffiles%2Ftest.html&charset=(detect+automatically)&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.654

_Aerospace_Eng_
05-12-2009, 10:55 AM
The second option should be this, sorry

<script type="text/javascript">
//<![CDATA[
function addElementBottom(){
var val = $F('newItemtxt');
new Insertion.Bottom('listOfElements', '<li>' + val + '</li>');
new Field.clear('newItemtxt');
}
//]]>
</script>
You can do that or put your javascript in a separate js file. If you don't want to do the second option then option 1 is the preferred method. So in your case

<script type="text/javascript">
//<![CDATA[

function getClock() {
var url = '../../clock.asp';
var myAjax = new Ajax.PeriodicalUpdater(
'clockArea',
url,
{
method: 'get',
frequency: 1,
//onSuccess: function(resp){ alert("Success","test");},
onFailure: function(resp) {alert("Failure : "+ resp.statusTest,"test");},
onException : function(resp, exception){alert("exception "+ exception,"test");}
});
}

function testDollar(){
var myElements = $('clockArea','clockArea2');
for (var i = 0; i < myElements.length; i++) {
myElements[i].innerHTML = "Value: " +i;
myElements[i].value = "Value: " + i;
alert(myElements[i].value,"test");
}
}
function removeElement(){
var toBeDeleted = $('clockArea2');
toBeDeleted.parentNode.removeChild(toBeDeleted);

}
function addElementBottom(){
var val = $F('newItemtxt');
new Insertion.Bottom('listOfElements', '<li>' + val + '</li>');
new Field.clear('newItemtxt');
}
function addElementTop(){
var val = $F('newItemtxt');
new Insertion.Top('listOfElements', '<li>' + val + '</li>');
new Field.clear('newItemtxt');
}
function addElementBefore(){
var val = $F('newItemtxt');
new Insertion.Before('listOfElements', '<h1>' + val + '</h1>');
new Field.clear('newItemtxt');
}
function addElementAfter(){
var val = $F('newItemtxt');
new Insertion.After('listOfElements', '<h1>' + val + '</h1>');
new Field.clear('newItemtxt');
}

function giveItATry() {
var value = Try.these (
function () {
return 5;
},
function () {
Alaa; // error
return 1;
}
);
alert("path: " + value);
}
function hideElement(){
$('headDiv').toggle(); // .hide + .show
}
//]]>
</script>
Which will pass validation if you make the change in your document. Again do not use the language attribute.

Alaa
05-12-2009, 11:25 AM
Thank you very much, It is valid now:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum