Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Transform form Input field into read-only after data is entered

I'm trying to find out if it's possible to update the below code with the following logic:
Once text is entered, make field read-only.
Basically, it's a signature field that we want to be locked as soon as someone enters a value.

<strong>Logistics Chief:</strong></span></td>
            <td><span style="font-size: 10pt; font-family: Arial;"><input type="text" style="width: 200px; height: 22px;" value="" fieldname="Field_31"><br>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This can be done with some vanilla JavaScript. Here are 2 functions written to lock and unlock the input field. Using the input's HTML attribute onfocusout="" we access the event for un-focusing the field, aka leaving the edit mode of the field. I then added a button to unlock it again, as the user will be mighty irritated if he/she managed to put a type-o in there and no alternative is available for fixing it.

The HTML:

<td>
    <span style="font-size: 10pt; font-family: Arial;">
        <input id="signature_input" onfocusout="lock_signature_field()" type="text" style="width: 200px; height: 22px;" fieldname="Field_31">
        <br><br>
    </span>
</td>
<td>
    <button type="button" name="button" onclick="unlock_signature_field()">Edit Signature</button>
</td>

Here's that same HTML again with less clutter, more copy-paste:able:

<td>
    <span>
        <input id="signature_input" onfocusout="lock_signature_field()" type="text"fieldname="name">
        <br><br>
    </span>
</td>
<td>
    <button type="button" name="button" onclick="unlock_signature_field()">Edit Signature</button>
</td>

The JS (put right before the in the bottom of the page):

<script type="text/javascript">

    // set reference to the dom input field
    const signatureField = document.getElementById("signature_input");

    function lock_signature_field() {
        signatureField.setAttribute('readonly', true);
        console.log('Element was locked.'); // you can remove this debug-line if you want.
    }

    function unlock_signature_field() {
        signatureField.removeAttribute("readonly"); // we have to remove the attribute alltogether, cause setting it to false, will do nothing in most browsers.
        console.log('Element was unlocked.'); // you can remove this debug-line if you want.
    }

</script>

Here it is in a jsfiddle!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!