I am trying to enable input field using mouse click, is there a way to achieve it?
Here’s what my interface looked like:
Note: It is required to disable first input fields and by clicked specific input text then it should be enabled.
I would like to enable once specific input field is clicked.
<?php foreach($grades as $grade): ?>
<td> <input type="text" class="form-control" value="<?php echo $grade['grade'] ?>" id="gradeid" disabled></td>
<?php endforeach; ?>
Script:
<script>
const inputField = document.getElementById('gradeid');
inputField.onfocus = () => {
$('#gradeid').attr('disabled', 'disabled''');
};
</script>
2
Answers
onclick
andonfocus
events won’t work when the button is disabled. However, you can add the event to the element that holds it.For example, here is the HTML:
and here’s the Javascript.
The browsers disable events on disabled elements. and when you to perform something on multiple fields you must class elements or dynamic id elements.
here is working demo hope this will help you to understand,