It will not work because php is a server-side pre-processor that cannot know anything about the user's browser other than what is provided in the browser's original request, which includes nothing about its current scripting capability.
Basically, if you want to have rich content beyond the simplistic noscript
tags -- they can only add non-scripted content, not hide scripted content -- you have to:
- Send all content -- both plain and javascript versions -- to the
browser.
- Place all non-scripted versions of the html in
div
or span
tags with class="nocript"
.
- Place all scripted versions of the html in
div
or span
tags with class="script"
.
- Set css to start with
div.noscript{display:block}
, span.noscript{display:inline}
, .script{display:none}
.
- Have your javascript hide each element with
class="noscript"
with element.style.display='none'
, show each div
with class="script"
with element.style.display='block'
and show each span
with class="script"
with element.style.display='inline'
.
You also have to consider that a browser is an especially hostile environment to be programming into, as the user, or any plugins, can do anything, like disable javascript, at any time. Therefore, you have to double-check everything that the browser sends, whether by form or AJAX, in your PHP code to make sure it is complete and not corrupt.