简体   繁体   中英

How do you you copy data from one field to another and append a text string in javascript

So I've got a pdf that is a form fillable student information card, my boss wants me to write javascript code that copies the whatever is typed in the username field into the email field and append the new text in the email field with @College.edu

So I've done bit of research and found a code snippet that gets the job half done with a function, but now I can't activate this function. All of my google searches either use jquery to get this done or html and I can't use either of those since I'm programming this in a pdf document

Here's the code I have so far:

 function copydata(){ var box1 = document.getElementById("Username"); var box2 = document.getElementById("Email"); box1.value = box2.value; } 

I tried everything I can think of to get this function to execute with like an onblur or onfocus method, I would be fine with it if it copied over as the person was typing into the first field. Nothing I do works however and the debugger console literally tells me nothing. Any help would be appreciated.

Form Fallible Debugger Error

Did you mean that?

 function handleChange(e) { document.getElementById("Email").value = e.target.value + "@College.edu"; } Username.addEventListener("keyup", handleChange, false); 
 <input type="text" id="Username" /> <input type="email" id="Email" /> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM