logo-dw

Go Back   Dreamweaver Club Forums > Graphic Design > Web Design
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 06-20-2007, 08:18 AM   #1
s_dragons_lair_c
 
Join Date: Jun 2005
Location: Kolkata, India
Posts: 16
Default learning javascript - i have a question

I dont know if this is the right place to put this question but i couldnt find any other place to put it either.

So Im learning javascript from a book and the following is one of its examples.

HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Date example</title>
<style type="text/css">
.error{color:#c00;font-weight:bold;}
</style>
<script type="text/javascript">
function checkDate(){
if(!document.getElementById || !document.createTextNode){return;}
var dateField=document.getElementById('date');
if(!dateField){return;}
var errorContainer=dateField.parentNode.getElementsByTagName('span')[0];
if(!errorContainer){return;}
var checkPattern=new RegExp("\\d{2}/\\d{2}/\\d{4}");
var errorMessage='';
errorContainer.firstChild.nodeValue=' ';
var dateValue=dateField.value;
if(dateValue==''){
errorMessage='Please provide a date.';
} else if(!checkPattern.test(dateValue)){
errorMessage='Please provide the date in the defined format.';
}
if(errorMessage!=''){
errorContainer.firstChild.nodeValue=errorMessage;
dateField.focus();
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<h1>Events search</h1>
<form action="eventssearch.php" method="post" onsubmit="return checkDate();">
<p> 
<label for="date">Date in the format DD/MM/YYYY:</label><br />
<input type="text" id="date" name="date" />
<input type="submit" value="Check " />
<br />(example 26/04/1975) <span class="error"> </span>
</p> 
</form>
</body>
</html>
The only problem is it doesnt actually give the error message. But I did find out that a small change does make the script to give the error message.
I changed the text between the span tags to &nbsp; and it started working.

But i cant figure out why that happened.
s_dragons_lair_c is offline   Reply With Quote
Old 06-20-2007, 09:29 AM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

thats a strange one

i use the innerHTML method which has always been good for me
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 06-21-2007, 02:10 AM   #3
s_dragons_lair_c
 
Join Date: Jun 2005
Location: Kolkata, India
Posts: 16
Default

sry but im not familiar with that method.
but im still curious to know abt my original prob.
so ur saying that it's not supposed to happen.
or maybe its because of the browsers i use. IE7 & Opera 9.21.
s_dragons_lair_c is offline   Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:18 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com