Current location: Hot Scripts Forums » General Web Coding » JavaScript » HTML/XHTML Problems


HTML/XHTML Problems

Reply
  #1 (permalink)  
Old 05-04-09, 04:41 AM
s20001321 s20001321 is offline
Newbie Coder
 
Join Date: May 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
HTML/XHTML Problems

I am a newbie in HTML/XHTML…I have met some problems when performing the specific tasks…

1 –

Code:
<script type = "text/javascript">

function EmailCheck()
    {
        var mail =  document.getElementById("email").value;
        var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
        if (!pattern.test(mail)) 
        {
            alert("Invalid Email Address");
        }
        else
        {
            alert("valid Email Address");
        }
    }
</script>

HTML Code:
<form  method="get" action="h ttp://xxxxxx.php">
<table border="1" cellspacing="0" cellpadding="2">
    <tr> 
      <th colspan="2">Newsletter Signup</th>
   </tr>
    <tr> 
      <td>Email</td>
      <td><input id="Email" type="text" /><input type="button" value="Check" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>Please send me newsletter<input id="monthly" type="checkbox" /></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><input type="submit" id="Send" value="Send" /></td>
    </tr>
  </table>
</form>
How to validate the E-mail address and send the email address to "h ttp://xxxxxx.php" at the same time by using “get” method when click the “Send” button?? Also, how to “Stop” action when the e-mail address is incorrect?


2 –

HTML Code:
<form id="feedback" method="post" action="h ttp://xxxxxx.php">
<table border="1" cellspacing="0" cellpadding="2">
    <tr> 
      <th colspan="2">Feedback Form</th>
    </tr>
    <tr> 
      <td>Name</td>
      <td><input id="name" type="text" /></td>
    </tr>
    <tr> 
      <td>Email</td>
      <td><input id="Email" type="text" /></td>
    </tr>
    <tr> 
      <td>Subject</td>
      <td><input id="Subject" type="text" /></td>
    </tr>
    <tr> 
      <td>Comments</td>
      <td><textarea id="textarea" cols="30" rows="10"></textarea></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><input type="submit" id="Send" value="Send" /></td>
    </tr>
  </table>
</form>
How to use JavaScript to validate all of the above fields including verifying the email address? Also, how to use “Post” method to send the information to "h ttp://xxxxxx.php" ??



3 –

HTML Code:
  <table border="2" cellspacing="3" cellpadding="4">
    <tr> 
      <th colspan="10">aaa</th>
    </tr>
    <tr> 
      <td><a href="xxx.htm"><img src="yyy.jpg" alt="zzz" /></a></td>


For this part, it needs to read the data from .txt file and is separated by “,”…and then display the content in the .htm...How to do it???

These are the few lines in .txt:
itemname,Price,size,in stock,colour

[Bedroom]
single bed,$160,single,yes,wood
double bed,$300,double,yes,wood


Million thanksss…

Last edited by Nico; 05-05-09 at 02:31 AM.
Reply With Quote
  #2 (permalink)  
Old 05-04-09, 08:19 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
In the first example you need to add the onsubmit event listener to the form element and the onclick event listener to the Check button.
Javascript Code:
  1. <script type = "text/javascript">
  2. var email_ok = 0;
  3. function EmailCheck()
  4. {
  5. var mail = document.getElementById("email").value;
  6. var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
  7. if (!pattern.test(mail))
  8. {
  9. alert("Invalid Email Address");
  10. }
  11. else
  12. {
  13. email_ok = 1;
  14. alert("valid Email Address");
  15. }
  16. }
  17. function sendForm()
  18. {
  19.  if(email_ok == 0){alert("You did not validate the email address");return false;}
  20.  if(document.getElementById("monthly").checked == false)
  21.  {
  22.   var con = confirm("Do you want to subscribe to our news letter.");
  23.   if(con == true){document.getElementById("monthly").checked = true;}
  24.   }
  25.  return true;
  26.  }
  27. </script>
  28. <form method="get" action="http://xxxxxx.php" onsubmit="return sendForm()">
  29. <table border="1" cellspacing="0" cellpadding="2">
  30. <tr>
  31. <th colspan="2">Newsletter Signup</th>
  32. </tr>
  33. <tr>
  34. <td>Email</td>
  35. <td><input id="Email" type="text" /><input type="button" value="Check" onclick="EmailCheck()"/></td>
  36. </tr>
  37. <tr>
  38. <td>&nbsp;</td>
  39. <td>Please send me newsletter<input id="monthly" type="checkbox" /></td>
  40. </tr>
  41. <tr>
  42. <td>&nbsp;</td>
  43. <td><input type="submit" id="Send" value="Send" /></td>
  44. </tr>
  45. </table>
  46. </form>

This is a simple way to do the second example.
Javascript Code:
  1. <script type = "text/javascript">
  2. function validateForm()
  3. {
  4.  var name = document.getElementById("name");
  5.  var emailCheck = EmailCheck();
  6.  var subject = document.getElementById("Subject");
  7.  var ta = document.getElementById("textarea");
  8.  if(name.value == ""){alert("You must enter your name.");return false;}
  9.  if(emailCheck == 0){alert("You did not enter a valid email.");return false;}
  10.  if(subject.value == ""){alert("You did not enter a subject.");return false;}
  11.  if(ta.value == ""){alert("You did not enter any comments.");return false;}
  12.  return true;
  13.  }
  14.  
  15. function EmailCheck()
  16. {
  17. var mail = document.getElementById("Email").value;
  18. var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
  19. if (!pattern.test(mail))
  20. {
  21. return 0;
  22. }
  23. else
  24. {
  25. return 1;
  26. }
  27. }
  28. </script>
  29. <form id="feedback" method="post" action="h ttp://xxxxxx.php" onsubmit="return validateForm();">
  30. <table border="1" cellspacing="0" cellpadding="2">
  31. <tr>
  32. <th colspan="2">Feedback Form</th>
  33. </tr>
  34. <tr>
  35. <td>Name</td>
  36. <td><input id="name" type="text" /></td>
  37. </tr>
  38. <tr>
  39. <td>Email</td>
  40. <td><input id="Email" type="text" /></td>
  41. </tr>
  42. <tr>
  43. <td>Subject</td>
  44. <td><input id="Subject" type="text" /></td>
  45. </tr>
  46. <tr>
  47. <td>Comments</td>
  48. <td><textarea id="textarea" cols="30" rows="10"></textarea></td>
  49. </tr>
  50. <tr>
  51. <td>&nbsp;</td>
  52. <td><input type="submit" id="Send" value="Send" /></td>
  53. </tr>
  54. </table>
  55. </form>

For your third question, I have never worked with the FileSystemObject, I always use PHP to perform those tasks.
But you can read on it here:
http://www.java2s.com/Tutorial/JavaS...stemObject.htm
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 05-04-09, 08:47 PM
s20001321 s20001321 is offline
Newbie Coder
 
Join Date: May 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Thank very much for your solutions...
and both of them are helpful for me!!

But there has a problem in Part1...
I can't go to the correct pages when sumbit the form@@...
Are there any mistakes in my code?
Code:
function EmailCheck()
{
var mail = document.getElementById("Email").value;
var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
if (!pattern.test(mail)){
	return 0;
}
else{
	return 1;
}
}

function sendForm()
{
var emailCheck = EmailCheck(); 
if(emailCheck == 0){
	alert("You did not validate the email address");
	return false;
}
if(document.getElementById("monthly").checked == false) { 
var con = confirm("Do you want to subscribe to our news letter.");
if(con == true)
{document.getElementById("monthly").checked = true;}
}
return true; 
}
</script>
…
<h2 id="signup">Why not sign up for our newsletter and receive the latest furniture news!</h2>
<form id="newsletter" method="get" action="h ttp://mercury.it.swin.edu.au/wd000000/signup.php" onsubmit="return sendForm()" >
<table border="1" cellspacing="0" cellpadding="2">
    <tr> 
      <th colspan="2">Newsletter Signup</th>
   </tr>
    <tr> 
      <td>Email</td>
      <td><input name="Email" type="text" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>Please send me the monthly newsletter<input name="monthly" type="checkbox" /></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><input type="submit" name="Send" value="Send" /></td>
    </tr>
  </table>
</form>
…

Last edited by Nico; 05-05-09 at 02:30 AM.
Reply With Quote
  #4 (permalink)  
Old 05-05-09, 05:37 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
I see two problems.

First, the action value in the form element isn't spelled right.
You have a space in the "http" part. (ie: h ttp)

And second, you are referencing the input elements by id, but you didn't give them any id's.

I also noticed that in my code I gave the input elements ids but not names.
You will need both to get your code working.
Javascript Code:
  1. <html>
  2. <head>
  3. <script>
  4. function EmailCheck()
  5. {
  6.  var mail = document.getElementById("Email").value;
  7.  var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
  8.  if(!pattern.test(mail)){return 0;}
  9.  else{return 1;}
  10.  }
  11.  
  12. function sendForm()
  13. {
  14.  var emailCheck = EmailCheck();
  15.  if(emailCheck == 0)
  16.  {
  17.   alert("You did not validate the email address");
  18.   return false;
  19.   }
  20.  if(document.getElementById("monthly").checked == false)
  21.  {
  22.   var con = confirm("Do you want to subscribe to our news letter.");
  23.   if(con == true){document.getElementById("monthly").checked = true;}
  24.   }
  25.  return true;
  26.  }
  27. </script>
  28. <body>
  29.  <h2 id="signup">Why not sign up for our newsletter and receive the latest furniture news!</h2>
  30.  <form id="newsletter" method="get" action="http://mercury.it.swin.edu.au/wd000000/signup.php" onsubmit="return sendForm();" >
  31.   <table border="1" cellspacing="0" cellpadding="2">
  32.    <tr>
  33.     <th colspan="2">Newsletter Signup</th>
  34.    </tr>
  35.    <tr>
  36.     <td>Email</td>
  37.     <td><input id="Email" name="Email" type="text" /></td>
  38.    </tr>
  39.    <tr>
  40.     <td>&nbsp;</td>
  41.     <td>Please send me the monthly newsletter<input id="monthly" name="monthly" type="checkbox" /></td>
  42.    </tr>
  43.    <tr>
  44.     <td>&nbsp;</td>
  45.     <td><input type="submit" name="Send" value="Send" /></td>
  46.    </tr>
  47.   </table>
  48.  </form>
  49. </body>
  50. </html>
__________________
Jerry Broughton

Last edited by job0107; 05-05-09 at 05:49 AM.
Reply With Quote
  #5 (permalink)  
Old 05-05-09, 05:40 AM
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
Quote:
Originally Posted by job0107 View Post
I see two problems.

First, the action value in the form element isn't spelled right.
You have a space in the "http" part. (ie: h ttp)
I'm guessing he did that on purpose, as his account hasn't met the requirements to post links yet.
Reply With Quote
  #6 (permalink)  
Old 05-05-09, 08:18 PM
s20001321 s20001321 is offline
Newbie Coder
 
Join Date: May 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Yes..I can't post the full link since I am a newbie here>.<
However..the problem is still the same which cannot pass the e-mail address to that specific link...
Here is my full coding..Is there any problem again(except the links)?

P.S. I am using XHTML1.0 Strict (it is a must...)

function EmailCheck()
{
var mail = document.getElementById("Email").value;
var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
if (!pattern.test(mail)){
return 0;
}
else{
return 1;
}
}

function sendForm()
{
var emailCheck = EmailCheck();
if(emailCheck == 0){
alert("You did not validate the email address");
return false;
}
if(document.getElementById("monthly").checked == false) {
var con = confirm("Do you want to subscribe to our news letter.");
if(con == true)
{document.getElementById("monthly").checked = true;}
}
return true;
}
</script>
</head>

<body>

<h2 id="signup">Why not sign up for our newsletter and receive the latest furniture news!</h2>
<form id="newsletter" method="get" action="h ttp://mercury.it.swin.edu.au/wd000000/signup.php" onsubmit="return sendForm()" >
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<th colspan="2">Newsletter Signup</th>
</tr>
<tr>
<td>Email</td>
<td><input id="Email" name="Email" type="text" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Please send me the monthly newsletter<input id="monthly" name="monthly" type="checkbox" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Send" value="Send" /></td>
</tr>
</table>
</form>


</body>
</html>
Reply With Quote
  #7 (permalink)  
Old 05-05-09, 11:10 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
This link should work:
HTML Code:
<a href="http://mercury.it.swin.edu.au/wd000000/signup.php?Email=myEmail@myMailBox.com&monthly=true&Send=Send">send</a>
And if it doesn't then there is something else wrong.

And this code should work also:
Javasecipt 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"><head><script>function EmailCheck(){ var mail = document.getElementById("Email").value; var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/; return pattern.test(mail)?mail:0; }function sendForm(){ var emailCheck = EmailCheck(); if(emailCheck == 0) {  alert("You did not validate the email address");  return false;  } if(document.getElementById("monthly").checked == false) {  var con = confirm("Do you want to subscribe to our news letter.");  if(con == true){document.getElementById("monthly").checked = true;}  } var url = "http://mercury.it.swin.edu.au/wd000000/signup.php"; var mtly = document.getElementById("monthly").checked == true ? 1 : 0; var url_temp = url + "?Email=" + emailCheck + "&monthly=" + mtly + "&Send=Send"; location.href = url_temp; }</script><style>#a1{ text-decoration:none; color:#222; border-left:2px solid #edf; border-top:2px solid #edf; border-right:2px solid #957299; border-bottom:2px solid #957299; padding-left:5px; padding-right:7px; width:50px; height:25px; margin-right:5px; background:#f0efff; }</style><body>… <h2 id="signup">Why not sign up for our newsletter and receive the latest furniture news!</h2>  <table border="1" cellspacing="0" cellpadding="2">   <tr>    <th colspan="2">Newsletter Signup</th>   </tr>   <tr>    <td>Email</td>    <td><input id="Email" type="text" /></td>   </tr>   <tr>    <td>&nbsp;</td>    <td>Please send me the monthly newsletter<input id="monthly" type="checkbox" /></td>   </tr>   <tr>    <td>&nbsp;</td>    <td><button onclick="return sendForm();">Send</a></td>   </tr>  </table> </form>…</body></html>
__________________
Jerry Broughton
Reply With Quote
  #8 (permalink)  
Old 05-06-09, 01:07 AM
s20001321 s20001321 is offline
Newbie Coder
 
Join Date: May 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
I can see
"Missing email address?
Did you send using the GET method?"
when I click the "Send button"...
What message did you see@@?
Reply With Quote
  #9 (permalink)  
Old 05-06-09, 09:49 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by s20001321 View Post
I can see
"Missing email address?
Did you send using the GET method?"
when I click the "Send button"...
What message did you see@@?
Yes, that is the error I get.
But I think I have found the problem.
The name of the email input element is "Email" when it should be "email".

Originally you gave an id="Email" but you didn't assign a name property.
So I assumed the name was also "Email".
I guess you didn't read your assignment very well.
And sense you didn't read the assignment then you didn't catch that error.

I have tried this script and it works fine every time.
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">
<head>
<script type = "text/javascript">
function sendForm()
{
 var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
 if(!pattern.test(document.getElementById("email").value)){alert("You did not validate the email address");return false;}
 if(document.getElementById("monthly").checked == false){if(confirm("Do you want to subscribe to our news letter.")){document.getElementById("monthly").checked = true;}}
 return true;
 }
</script>
</head>
<body>
<form method="get" action="http://mercury.it.swin.edu.au/wd000000/signup.php" onsubmit="return sendForm()">
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<th colspan="2">Newsletter Signup</th>
</tr>
<tr>
<td>Email</td>
<td><input id="email" name="email" type="text" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Please send me newsletter<input id="monthly" name="monthly" type="checkbox" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" iname="Send" value="Send" /></td>
</tr>
</table>
</form>
</body>
</html>
__________________
Jerry Broughton
Reply With Quote
  #10 (permalink)  
Old 05-07-09, 02:50 AM
s20001321 s20001321 is offline
Newbie Coder
 
Join Date: May 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by job0107 View Post
Yes, that is the error I get.
But I think I have found the problem.
The name of the email input element is "Email" when it should be "email".

Originally you gave an id="Email" but you didn't assign a name property.
So I assumed the name was also "Email".
I guess you didn't read your assignment very well.
And sense you didn't read the assignment then you didn't catch that error.

I have tried this script and it works fine every time.
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">
<head>
<script type = "text/javascript">
function sendForm()
{
 var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
 if(!pattern.test(document.getElementById("email").value)){alert("You did not validate the email address");return false;}
 if(document.getElementById("monthly").checked == false){if(confirm("Do you want to subscribe to our news letter.")){document.getElementById("monthly").checked = true;}}
 return true;
 }
</script>
</head>
<body>
<form method="get" action="http://mercury.it.swin.edu.au/wd000000/signup.php" onsubmit="return sendForm()">
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<th colspan="2">Newsletter Signup</th>
</tr>
<tr>
<td>Email</td>
<td><input id="email" name="email" type="text" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Please send me newsletter<input id="monthly" name="monthly" type="checkbox" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" iname="Send" value="Send" /></td>
</tr>
</table>
</form>
</body>
</html>
Thank you very mcuh!!!!!!
Part 1 & 2 are OK now~
You are very helpful for me...^^

For part 3...
I think I need to ask the lecturer again because I and some of the net friends cannot get the meaning from the requirement...However, do you understand the meaning of the below requirement for part 3@@?

This is a single “prototype” catalogue page that contains a table (or tables) of all the product items
from one of the categories on offer. (In the second assignment, the content will be generated using
database information and server-side programming allowing all of the categories to be included!)
• For each product item show the thumbnail image and basic details: item name and cost.
o The file details.txt has all the details available. The details are separated by commas.
Hint: It may be worth “importing” and then “exporting” the text file with Excel, but make sure you
clean up the resulting HTML!
• There are many products available, but you only need to show the products for your chosen
category.
• If the visitor clicks on an image we would want to show them more details,
o This is just a prototype site and we don’t have all the images and details yet.
o Make all of the items (the text and/or images) as link to the “details_1.shtml” prototype
page. i.e. no matter which category the user selects the same product will show.
(Assignment 2 will extend this so that the selected product will show)
• You can use a table to present the catalogue data (+CSS), but you must use <th> (heading)
elements for heading cells, and provide a suitable caption and summary for the table
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
Problems with event binding eddiefisher41 HTML/XHTML/XML 5 03-10-09 12:36 AM
Excel Problems Using VMWare DarleneMiles New Members & Introductions 0 02-20-09 10:38 AM
HTML Beginner Problems gasper000 HTML/XHTML/XML 2 08-27-08 07:35 PM
Any problems with Java includes?? Rachy222 JavaScript 1 12-10-07 04:53 PM
IE problems with encoding and displaying pages kittenesque HTML/XHTML/XML 1 10-21-06 04:59 PM


All times are GMT -5. The time now is 11:50 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.