Forum Moderators: open
My attempt looked like
<noscript>my error message <div style="display:none;visibility:hidden;"></noscript>
my form here
<noscript></div></noscript>
But that obviously didn't work (otherwise I wouldn't be here :P). Any suggestions? Thanks.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title></title>
<style type="text/css">
#myForm {
display: none;
}
.hasJs #jsRequired {
display: none;
}
.hasJs #myForm {
display: block;
}
</style>
</head>
<body>
<div id="myForm">
...
</div>
<div id="jsRequired">
error message here
</div>
<script type="text/javascript" src="http://yui.yahooapis.com/2.5.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {
YAHOO.util.Dom.addClass(document.body, 'hasJs');
});
</script>
</body>
</html>
<?php if(false){ ?>
content here!
<?php } ?>
You should take an opposite approach: show the error message by default. But use JS to replace the message with your form, by rewriting the innerHTML of its element container.
That way users who have JS disabled will see the error content, users with JS will see the form.
You could even go a step further to keep it tidy: put the form HTML in an external *.html file, and load it onto the page using a standard AJAX library like those found in Jquery or Mootools. This can be done with 3 lines of code, max!