By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

The "and" operator not validating

P: 59
I am in a JavaScript class, and we have to get all of our code to validate at the w3c website... Here is my code, it does what I want it to do which is require the user to enter the name and either the address of the email address, but when I try to validate it through w3c, I get the following errors... Can anyone help?

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6. <title>Customer Login Screen</title>
  7. <style type="text/css">
  8. <!--
  9. .style1 {
  10.     font-size: 24px;
  11.     font-weight: bold;
  12. }
  13. body {
  14.     background-color: #C69C98;
  15. }
  16. -->
  17. </style>
  18.  
  19. <script type="text/JavaScript">
  20. function submitForm()
  21. {
  22.    if (document.form1.name.value == "")
  23.    {
  24.    window.alert("You must enter your name!");
  25.    return false;      
  26.    }
  27.    else if (document.form1.address.value == "" && document.form1.email.value == "")
  28.     {
  29.     window.alert("Please enter either your mailing address or your email address.");
  30.     return false;
  31.     }
  32.    else 
  33.    window.open('SRTY.html');
  34.    return true;
  35. }
  36. </script>
  37.  
  38. </head>
  39.  
  40. <body>
  41. <p class="style1"><img src="Kudler-food-blk.gif" alt="Logo" width="275" height="146" /> </p>
  42. <p class="style1">Join Our Mailing List!!  </p>
  43. <table width="358" border="0">
  44.   <tr>
  45.     <td width="9">&nbsp;</td>
  46.     <td width="312">&nbsp;</td>
  47.     <td width="23">&nbsp;</td>
  48.   </tr>
  49.   <tr>
  50.     <td>&nbsp;</td>
  51.     <td>
  52.     <form id="form1" name="form1" method="post" action="">
  53.       <p>Customer Name:
  54.         <input type="text" name="name"/>
  55.         </p>
  56.       <p>Mailing Address:
  57.         <input type="text" name="address"/>
  58.         </p>
  59.       <p>Email Address:
  60.         <input type="text" name="email"/>      
  61.         </p>
  62.       <p>Telephone Number:
  63.         <input type="text" name="phone"/>
  64.       </p>
  65.       <p align="left">&nbsp;</p>
  66.       <p align="left">
  67.         <input type="submit" value="Submit" onclick="return submitForm();"/>
  68.         <input type="reset"/>
  69.       </p>
  70.     </form></td>
  71.     <td>&nbsp;</td>
  72.   </tr>
  73.   <tr>
  74.     <td>&nbsp;</td>
  75.     <td>&nbsp;</td>
  76.     <td>&nbsp;</td>
  77.   </tr>
  78. </table>
  79. <p><a href="http://validator.w3.org/check?uri=referer"><img
  80.         src="http://www.w3.org/Icons/valid-xhtml10-blue"
  81.         alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></p>
  82. </body>
  83. </html>
  84.  


Here are the errors...

Validation Output: 2 Errors

1. Warning Line 26, Column 47: character "&" is the first character of a delimiter but occurred as data.

else if (document.form1.address.value == "" && document.form1.email.value == "")

This message may appear in several cases:
* You tried to include the "<" character in your page: you should escape it as "&lt;"
* You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
* Another possibility is that you forgot to close quotes in a previous tag.

2. Warning Line 26, Column 48: character "&" is the first character of a delimiter but occurred as data.

else if (document.form1.address.value == "" && document.form1.email.value == "")

This message may appear in several cases:
* You tried to include the "<" character in your page: you should escape it as "&lt;"
* You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
* Another possibility is that you forgot to close quotes in a previous tag.


3. Error Line 26, Column 48: XML Parsing Error: xmlParseEntityRef: no name.

else if (document.form1.address.value == "" && document.form1.email.value == "")


4. Error Line 26, Column 49: XML Parsing Error: xmlParseEntityRef: no name.

else if (document.form1.address.value == "" && document.form1.email.value == "")
Nov 2 '07 #1
Share this Question
Share on Google+
1 Reply


100+
P: 210
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
With that doctype your code needs to be placed wthin a CDATA island.
Nov 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.