Welcome to WebmasterWorld Guest from 54.158.51.150

Forum Moderators: open

Message Too Old, No Replies

Can anyone see what id wrong with this simple script?

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

5+ Year Member



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>

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

WebmasterWorld Senior Member 10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month