homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Can anyone see what id wrong with this simple script?
horseatingweeds




msg:3426186
 6:11 pm on Aug 19, 2007 (gmt 0)

I'm innocently putting together a validation script but then I get this error: error_name has no properties - in the .style line...

<html>
<head>
<script language="javascript" type="text/javascript">
var error_name = document.getElementById('error_name');
error_name.style.position = 'static';
</script>
</head>
<body>
<p class='error' id='error_name'>Please enter you name.</p>
<p class='error' id='error_email'>Please enter a valid email address.</p>
<p class='error' id='error_remail'>Your email addresses do not match. Please reenter them.</p>
<p class='error' id='error_subject'>You did not enter a subject.</p>
<p class='error' id='error_message'>Tou did not enter a message.</p>

</body>
</html>

 

birdbrain




msg:3426642
 9:28 am on Aug 20, 2007 (gmt 0)

Hi there horseatingweeds,

the div with the id - error_name does not exist until the page is loaded.
You need to allow for this in your script...


<script type="text/javascript">
window.onload=function(){
var error_name=document.getElementById('error_name');
error_name.style.position='static';
}
</script>

Also note that language=javascript is deprecated and should not be used. ;)

birdbrain

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved