- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Auto-filling one field same as other
To auto-filling one field same as other, the JavaScript script is as follows −
Example
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h1>JavaScript Auto-filling one field same as other</h1> <h2>Enter your primary address</h2> Address<input class="address" type="text" /> Pin Code<input class="pincode" type="text" /> <h4>Secondary Address same as primary</h4> <input class="check" type="checkbox" /> Same Address <h2>Enter your secondary address</h2> Address<input class="address" type="text" /> Pin Code<input class="pincode" type="text" /> <script type="text/javascript"> let checkEle = document.querySelector(".check"); let addressEle = document.querySelectorAll(".address"); let pinCodeEle = document.querySelectorAll(".pincode"); checkEle.addEventListener("change", (event) => { if (event.target.checked) { console.log(addressEle[0].value); addressEle[1].value = addressEle[0].value; pinCodeEle[1].value = pinCodeEle[0].value; } }); </script> </body> </html>
Output
On filling the primary address and clicking the “Same Address” checkbox −
- Related Articles
- How to autofill a field in JavaScript same as another?
- In SAP system, auto filling of NAME_1 while entering client number
- How to reduce an array while merging one of its field as well in JavaScript
- MongoDB query to select one field if the other is null?
- Comparing and filling arrays in JavaScript
- Fetch max date and other field from the same row of a table grouped by other fields in SAP HANA
- Create many JavaScript objects as the same type?
- Complete Equation by Filling Missing Operator in JavaScript
- MongoDB query to select one field if the other is null and the first field if both are not null?
- Using one array to help filter the other in JavaScript
- Can one string be repeated to form other in JavaScript
- Make HTML text input field grow as I type in JavaScript?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- MongoDB Aggregate JSON array field for the matching field of other collection?
- Write one word which means the same as ‘moving with a negative acceleration’.

Advertisements