Check if JavaScript is enable using PHP | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Check if JavaScript is enable using PHP

Hi everyone, i want to check if javascript is enabled in client side using PHP. In particular i want to do this because i want check data input from a form: So, if javascript is enabled in client side, check the data and, if are correct send the data checked to server that no check the data; Otherwise check data input in server side using php. The form input is like: - name(10 char max) - tel (0×-×××[-]×××[×]) button send, button reset

23rd Jun 2017, 6:58 AM
Angelo Salvatore Graceffa
Angelo Salvatore Graceffa - avatar
7 Antworten
+ 6
In a more general thinking, it's a good idea to use less JS as possible, and reserv it to not mandatory enhancement to preserv user experience in all cases ;)
23rd Jun 2017, 8:15 AM
visph
visph - avatar
+ 5
Design your form as without JS handled, and with JS modify dynamically this behaviour on page load (so it doesn't happen when JS disabled or unavailable )... Commonly and basically, in JS part, you have to retrieve the value of the "action" attribute value of the form, and attach your "onsubmit' event to the form and/or the button(s), as well as attach "onchange" and/or "oninput" to check values on the fly ^^ Anyway, right good way (and sometimes only way) to attach event to an element is to use the addEventListener() method of the DOM API ;)
23rd Jun 2017, 8:01 AM
visph
visph - avatar
+ 1
Thank you! =) it's a good idea!
23rd Jun 2017, 8:09 AM
Angelo Salvatore Graceffa
Angelo Salvatore Graceffa - avatar
0
If your site NEEDS Javascript you can always add <noscript> Please activate JavaScript</noscript>
23rd Jun 2017, 7:06 AM
Limitless
Limitless - avatar
0
Yes, i know.. infact in noscript tag i put my code that return a message if javascript is not enabled. My problem is, if in attribute onclick i call the javascript function, this will work iff javascript is enabled and no otherwise! I want to change this button send in order to call javascript function if javascript is enabled, and send the data non checked at the server if javascript is not enabled. Any idea?
23rd Jun 2017, 7:18 AM
Angelo Salvatore Graceffa
Angelo Salvatore Graceffa - avatar
0
So if JavaScript is enabled he can use it and if not he can't? I think you should try creating the form with JavaScript so that when JavaScript is disabled there's no form that'll​ load
23rd Jun 2017, 7:21 AM
Limitless
Limitless - avatar
0
yes.. but the form is mandatory.. so the form will be created with html.. JS enabled: form--> check data--> if data is correct,send to server, if not correct the user will be alert JS disabled: form--> send data to server that check if data are correct or no
23rd Jun 2017, 7:27 AM
Angelo Salvatore Graceffa
Angelo Salvatore Graceffa - avatar