Here is my input field disabled code
<input type="text" class="empl_date form-control" id="staffid" name="staffid" value="<?php echo $employeeworks[0]['employeeCode'];?>" arsley-maxlength="6" placeholder=" Schedule Date" disabled />
How can i prevent inspect element option in this field?
You can prevent inspect by right click.
This way to prevent right click
If user press F12 and click arrow button and inspect, it still ok. You also can prevent F12 by this code
No it's not possible.
Code inspectors are designed for debugging HTML and Javascript. They will always do show the live
DOM
object of web page. It means that it reveals the HTML code of everything you see on the page, even if they're generated by Javascript.Actually, you can not restrict user to check inspect element of any specific element but you can disable completely. Check below code which will not allow user to open debugger and not even page source.
But this code also has some missings as well. Hope it helps you.
As mentioned in other answers, it can't be prevented fully, once it is in the browser, user can manipulate it. Rather than thinking how to prevent the inspect element or dev tools being used on your input, you should think about your goal, what do you want to achieve with this?
If you want to prevent from input value being changed, use some hash generated on server side, that includes value from your
staffid
field and store it in hidden input.When user submits the form, just regenerate hash using
staffid
value and hash value from input. If they don't match, user has manipulated thestaffid
input manually.Example:
and then on submission:
Try This,