How to implement HTML to detect that input is complete and automatically fill in the next content

How to implement HTML to detect that input is complete and automatically fill in the next content

In the previous article, we have realized the simple detection of input completion. Now we will go a step further and realize the automatic filling of the next content after the input is completed.

When we need to automatically fill in the content and do not want it to be changed, we need to add the readonly attribute.

Functional requirements

When filling out the reimbursement document, you only need to fill in the number of days of the business trip to automatically calculate the amount of the business trip subsidy.

The code is as follows

HTML code:

<tbody>
    <tr style="background-color:#FfFFFF">
        <th colspan="2" class="info">Business trip allowance:</th>
    </tr>
    <tr style="background-color:#F3F3F3">
        <th>Subsidy days:</th>
        <td>
            <input class="form-control" onBlur="finnishInput(event)" "onInput(event)" id="travelAllowanceDaysId" type="number" placeholder="">
        </td>
    </tr>
    <tr style="background-color:#FFFFFF">
        <th>Subsidy amount:</th>
        <td>
            <input class="form-control" id="travelAllowanceFeesId" type="number" placeholder="">
        </td>
    </tr>
</tbody>

JavaScript code:

var flag = 0;

function onInput(e) {
    console.log("Inputing");
    flag = 1;
    $api.removeAttr($api.byId('travelAllowanceFeesId'), 'readonly');
}

function finishInput(e) {
    if (1 == flag) {
        console.log("InputOk");
        flag = 0;

        $api.byId('travelAllowanceFeesId').value = 400*$api.byId('travelAllowanceDaysId').value;
        $api.attr($api.byId('travelAllowanceFeesId'), 'readonly', true);
    }
}

The results are as follows

Summarize

The above is the implementation method of automatically filling in the next content after HTML detection input is completed. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  Detailed explanation of non-parent-child component communication in Vue3

>>:  Docker Modify Docker storage location Modify container image size limit operation

Recommend

Solution to the timeout problem when installing docker-compose with PIP

1: Installation command pip install docker-compos...

Use CSS3 to implement button hover flash dynamic special effects code

We have introduced how to create a waterfall layo...

A brief discussion on CSS3 animation jamming solutions

Why is it stuck? There is a premise that must be ...

Ajax jquery realizes the refresh effect of a div on the page

The original code is this: <div class='con...

Implementation of Docker container connection and communication

Port mapping is not the only way to connect Docke...

How to install Solr 8.6.2 in Docker and configure the Chinese word segmenter

1. Environment version Docker version 19.03.12 ce...

HTML+CSS implementation code for rounded rectangle

I was bored and suddenly thought of the implementa...

HTML pop-up div is very useful to realize mobile centering

Copy code The code is as follows: <!DOCTYPE ht...

Mini Program to Implement Paging Effect

This article example shares the specific code for...

Why MySQL can ignore time zone issues when using timestamp?

I have always wondered why the MySQL database tim...

Three common uses of openlayers6 map overlay (popup window marker text)

Table of contents 1. Write in front 2. Overlay to...

MySQL data type details

Table of contents 1. Numeric Type 1.1 Classificat...

How to pass parameters to JS via CSS

1. Background that needs to be passed through CSS...

JavaScript color viewer

This article example shares the specific code of ...