Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting if javascript is enabled

Status
Not open for further replies.

Geee

Programmer
Apr 23, 2001
253
GB
Hi, I want to do just that!

I would like to use PHP to detect if javascript is enabled in the browser. If it is enabled, I would like javascript to modify a text box, if it's not, i'd like the form to submit. Obviously, I need to detect if javascript is enabled using php and modify the form html consiquentially. I have googled this but without much luck. Does anyone know how to do this in PHP please?

-Geeeeeeeeeeeeeeeeeeeeeeee-
-=
 
php is a server side scripting technology. it can't detect what happens on the client.

but what you can do is use php to insert some javascript which, say, refreshes the page with a querystring or cookie or whatever so that on the next time around you can use php to test the querystring and/or cookie or whatever and take action appropriately.

there are loads of javascript sniffers on the web that might help you.
 
Obviously PHP is a server side technology, but to say that it can't detect the client just isn't true. You can tell the client's browser make, operating system and other things from PHP, so I was wondering if it was possible to do something similar with javascript.

On another note, what you have suggest is an excellent idea, and one I will be looking at now, thanks!

-Geeeeeeeeeeeeeeeeeeeeeeee-
-=
 
Another idea would be to use the onSubmit attribute of the form tag. If javascript is disabled then the browser should ignore the onSumit call and simply submit the form. I tested this on FireFox 1.5 and it did work. I did not test it in other browsers.

As a side note:
Geee said:
Obviously PHP is a server side technology, but to say that it can't detect the client just isn't true.
jpadie never said PHP cannot detect the client. jpadie actually said:
jpadie said:
it can't detect what happens on the client
Also, I have to respectfully disagree with your statement. The client connects to the web server, the web server receives the client information through HTTP headers (which can easily be faked) then stores the information and PHP references the web server info, not the client. So there is a clear separation between PHP and the client.

If I am mistaken then please correct me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top