Current location: Hot Scripts Forums » General Web Coding » JavaScript » how to validate this js code for xhtml strict


how to validate this js code for xhtml strict

Reply
  #1 (permalink)  
Old 09-27-09, 06:39 AM
kevinkhan kevinkhan is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes how to validate this js code for xhtml strict

This the html code below. Im getting a few errors

1) there is no attribute "onload" and
2) there is no attribute "name"

PHP Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <
head>
  <
meta http-equiv="content-type" content="text/html; charset=utf-8" />
  
<
title>Navigation</title>



<
link href="css/new.css" rel="stylesheet" type="text/css"/>

 <
script type="text/javascript" src="js/nav.js"></script>
</head>

<body onload="MM_preloadImages('images/tab1.gif','images/tab1hover.gif','images/tab2hover.gif','images/tab3hover.gif','images/tab4hover.gif','images/tab5hover.gif')">
  <div id="wrapper">

    <div id="top">
      <div id="topright">  
        
       <div id="primaryNavWrapper">
        <div id="primaryNav">
          <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab1','images/tab1hover.gif',1)" onmouseover="MM_nbGroup('over','tab1','images/tab1hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab1hover.gif" alt="Home" name="tab1" width="79" height="31" id="home" onload="MM_nbGroup('init','group1','tab1','images/tab1.gif',1)" /></a>
          <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab2','images/tab2hover.gif',1)" onmouseover="MM_nbGroup('over','tab2','images/tab2hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab2.gif" alt="About Us" name="tab2" width="95" height="31" id="aboutUs" /></a>
          <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab3','images/tab3hover.gif',1)" onmouseover="MM_nbGroup('over','tab3','images/tab3hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab3.gif" alt="Services" name="tab3" width="89" height="31" id="services" /></a>
          <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab4','images/tab4hover.gif',1)" onmouseover="MM_nbGroup('over','tab4','images/tab4hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab4.gif" alt="Testimonials" name="tab4" width="120" height="31" id="testimonials" /></a>
          <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab5','images/tab5hover.gif',1)" onmouseover="MM_nbGroup('over','tab5','images/tab5hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab5.gif" alt="Contact Us" name="tab5" width="108" height="31" id="contactUs"  /></a>        
        </div>
      </div>
    </div>
  </div>
  </div>
  
</body>
</html> 
and here is the js code

PHP Code:

function MM_preloadImages() { //v3.0

  
var d=document; if(d.images){ if(!d.MM_pd.MM_p=new Array();
    var 
i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0i<a.lengthi++)
    if (
a[i].indexOf("#")!=0){ d.MM_p[j]=new Imaged.MM_p[j++].src=a[i];}}
}

function 
MM_findObj(nd) { //v4.01
  
var p,i,x;  if(!dd=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    
d=parent.frames[n.substring(p+1)].documentn=n.substring(0,p);}
  if(!(
x=d[n])&&d.allx=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(
i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!
&& d.getElementByIdx=d.getElementById(n); return x;
}

function 
MM_nbGroup(eventgrpName) { //v6.0
  
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (
event == "init" && args.length 2) {
    if ((
img MM_findObj(args[2])) != null && !img.MM_init) {
      
img.MM_init trueimg.MM_up args[3]; img.MM_dn img.src;
      if ((
nbArr document[grpName]) == nullnbArr document[grpName] = new Array();
      
nbArr[nbArr.length] = img;
      for (
i=4args.length-1i+=2) if ((img MM_findObj(args[i])) != null) {
        if (!
img.MM_upimg.MM_up img.src;
        
img.src img.MM_dn args[i+1];
        
nbArr[nbArr.length] = img;
    } }
  } else if (
event == "over") {
    
document.MM_nbOver nbArr = new Array();
    for (
i=1args.length-1i+=3) if ((img MM_findObj(args[i])) != null) {
      if (!
img.MM_upimg.MM_up img.src;
      
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      
nbArr[nbArr.length] = img;
    }
  } else if (
event == "out" ) {
    for (
i=0document.MM_nbOver.lengthi++) {
      
img document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn img.MM_up; }
  } else if (
event == "down") {
    
nbArr document[grpName];
    if (
nbArr)
      for (
i=0nbArr.lengthi++) { img=nbArr[i]; img.src img.MM_upimg.MM_dn 0; }
    
document[grpName] = nbArr = new Array();
    for (
i=2args.length-1i+=2) if ((img MM_findObj(args[i])) != null) {
      if (!
img.MM_upimg.MM_up img.src;
      
img.src img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      
nbArr[nbArr.length] = img;
  } }

Any help would be greatly appreciated
Reply With Quote
  #2 (permalink)  
Old 09-27-09, 02:59 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
This code looks like it was generated by Dreamweaver, and it may not validate.

Does it have to be XHTML strict? If you choose a different standard, it will probably validate.

HTML doctype declaration
Reply With Quote
  #3 (permalink)  
Old 09-27-09, 03:37 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Remove your onload attribute from the <body> tag and place this in the <head>:
Code:
<script type="text/javascript">
window.onload = function()
{
    MM_preloadImages('images/tab1.gif','images/tab1hover.gif','images/tab2hover.gif','images/tab3hover.gif','images/tab4hover.gif','images/tab5hover.gif');
}
</script>
... and try removing the "name" attributes from your <img> tags. They might be redundant.
Reply With Quote
  #4 (permalink)  
Old 09-27-09, 07:27 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
The note about the name attribute is because the id attribute replaces the name attribute in XHTML (XHTML Syntax).
Reply With Quote
  #5 (permalink)  
Old 09-28-09, 03:28 AM
kevinkhan kevinkhan is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Nico View Post
... and try removing the "name" attributes from your <img> tags. They might be redundant.
Iv tryed this but they are required..

Yes this code was produced by dream weaver which probably isnt the best...

Does anyone have a link to where i can find cleaner code and code that will validate as html stict??

Thanks for your help...
Reply With Quote
  #6 (permalink)  
Old 09-28-09, 06:55 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
You could just run it through the validator until it validates.

It won't be true Dreamweaver code, but it will be valid.

The errors reported are minor enough that you should be able to get it to validate fairly fast.

The alternative is to hand-code it - don't use Dreamweaver. A good book is HeadFirst HTML/CSS.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Explanation of Code... Please davidk19380 Perl 1 02-26-06 01:50 PM
Zip Code search range errors Merovingian PHP 2 02-09-06 03:33 PM
Have a look at my JSP code which is not giving me the desired output j.gohel Everything Java 1 04-07-05 03:55 AM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 10:15 AM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 12:10 PM


All times are GMT -5. The time now is 01:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.