In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?

As pointed out in this answer, Django 1.9 added the Field.disabled attribute: The disabled boolean argument, when set to True, disables a form field using the disabled HTML attribute so that it won’t be editable by users. Even if a user tampers with the field’s value submitted to the server, it will be ignored in … Read more

Clearing using jQuery

Easy: you wrap a <form> around the element, call reset on the form, then remove the form using .unwrap(). Unlike the .clone() solutions otherwise in this thread, you end up with the same element at the end (including custom properties that were set on it). Tested and working in Opera, Firefox, Safari, Chrome and IE6+. … Read more

Best way to track onchange as-you-type in input type=”text”?

These days listen for oninput. It feels like onchange without the need to lose focus on the element. It is HTML5. It’s supported by everyone (even mobile), except IE8 and below. For IE add onpropertychange. I use it like this: const source = document.getElementById(‘source’); const result = document.getElementById(‘result’); const inputHandler = function(e) { result.innerHTML = … Read more

Twitter Bootstrap Form File Element Upload Button

Here’s a solution for Bootstrap 3, 4, and 5. To make a functional file input control that looks like a button, you only need HTML: HTML <label class=”btn btn-default”> Browse <input type=”file” hidden> </label> This works in all modern browsers, including IE9+. If you need support for old IE as well, please use the legacy … Read more

Two submit buttons in one form

Solution 1: Give each input a different value and keep the same name: <input type=”submit” name=”action” value=”Update” /> <input type=”submit” name=”action” value=”Delete” /> Then in the code check to see which was triggered: if ($_POST[‘action’] == ‘Update’) { //action for update here } else if ($_POST[‘action’] == ‘Delete’) { //action for delete } else { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)