Hey
I am having a problem trying to echo some javascript code in my php code.
I have a simple enough table where by a user can enter their email address to subscribe to the newsletter and using javascript have got the onfocus/on blur to remove the ‘Enter Email Address’ when the user clicks in the box, if there is nothing in the box it comes up ‘Enter Email Address again’ and so on as seen below:
<form name="newsletter" method="post" action="">
<table id="newsletter"><tr><td class="emailtxt"><h6>Sign up to our motoring newsletter</h6></td>
<td class="emailbox"><input type="text" name="email" size="30" value="Enter Email Address" onfocus="if(this.value.substr(0,5) == 'Enter') this.value='';" onblur="if(this.value.length < 1) this.value='Enter Email Address';"><input class="go" type="submit" value="" name="submit"></td>
</tr></table></form>
Now the problem is when i try to include this inside an php echo, if the form has been submitted the response will be a thank you (I will be adding in validation for the input as well once this is sorted), if not then the table needs to be displayed with the javascript onfocus/onblur working as talked about above. This however is not working and i cannot work out why. Code is shown below:
<?php
if (isset($_POST['submit'])) {
echo '
<form name="newsletter" method="post" action="">
<table id="newsletter"><tr><td class="emailtxt"><h6>Thank you. You are now signed up to our newsletter</h6></td>
</tr></table></form>';
} else {
echo '
<form name="newsletter" method="post" action="">
<table id="newsletter"><tr><td class="emailtxt"><h6>Sign up to our newsletter for the latest news, offers and updates</h6></td>
<td class="emailbox"><input type="text" name="email" size="30" value="Enter Email Address" onfocus="if(this.value.substr(0,5) == "Enter") this.value=""" onblur="if(this.value.length < 1) this.value="Enter Email Address""><input class="go" type="submit" value="" name="submit"></td>
</tr></table></form>
';
}
?>
Any help very much appreciated
Thanks
Jon