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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    XHTML Validation

    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?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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
    Code:
    <script src="pathtoyourjsfile.js" type="text/javascript"></script>
    Be sure to change the src part.
    Option 2
    Change your code to look like this
    Code:
    <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
    Code:
    <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.
    Last edited by _Aerospace_Eng_; 05-12-2009 at 09:44 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    It would help to have all your code or better still a link to your site.

    Frank
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    JS and XHTML

    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=ht...idator%2F1.654
    Last edited by Alaa; 05-12-2009 at 10:19 AM.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The second option should be this, sorry
    Code:
    <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
    Code:
    <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.
    Last edited by _Aerospace_Eng_; 05-12-2009 at 10:57 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Alaa (05-12-2009)

  • #6
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you very much, It is valid now


  •  

    Posting Permissions

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