I'm wondering if it's possible for a script to enable/disable all input elements on the page with some sort of toggle button.
I googled it but didn't find anything too useful except for this:
http://www.codetoad.com/javascript/enable_disable_form_element.asp but I'm not sure how to edit it for the toggle.
The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable. Tip: Disabled <input> elements in a form will not be submitted!
you can disable via css: pointer-events: none; Doesn't work everywhere though. Text input can still be tabbed into.
You can disable F12, right click, ctrl button etc. If the information being edited so sensitive that "it is scary" just validate server side. They can use tools like fiddler to make Http Requests that you don't desire.
Something like this would work:
var inputs=document.getElementsByTagName('input'); for(i=0;i<inputs.length;i++){ inputs[i].disabled=true; }
A working example:
$().ready(function() { $('#clicker').click(function() { $('input').each(function() { if ($(this).attr('disabled')) { $(this).removeAttr('disabled'); } else { $(this).attr({ 'disabled': 'disabled' }); } }); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <input type='text'></input> <input type='text'></input> <input type='text'></input> <div id='clicker' style='background-color:#FF0000; height:40px; width:100px;'></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With