Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vikramjeet-dev/a9f0eeb11c483647b26692afd11b7e89 to your computer and use it in GitHub Desktop.
Save vikramjeet-dev/a9f0eeb11c483647b26692afd11b7e89 to your computer and use it in GitHub Desktop.
Set another input type value same as entered previously .
//html input type
<input id="current_census" type="text" value="100" onkeyup="findPPD(this.id)">
<br>
<input type="text" id="rn_lvn_census" value="100" onkeyup="findPPD(this.id)">
<br>
<input type="text" id="cna_rna_census" value="100" onkeyup="findPPD(this.id)">
<br>
<input type="text" id="data" value="100" onkeyup="findPPD(this.id)">
<br>
<input type="text" id="census" value="100" onkeyup="findPPD(this.id)">
<br>
<input type="text" id="data1" value="100" onkeyup="findPPD(this.id)">
<br>
<input type="text" id="data2" value="100" onkeyup="findPPD(this.id)">
//this is where the magic happens
<script type="text/javascript">
function findPPD(id){
var idVal = document.getElementById(id).value;
document.getElementById(id).value = (idVal>0)?parseInt(idVal, 10):0;
var cur_census = document.getElementById(id).value;
document.getElementById('rn_lvn_census').value = document.getElementById('cna_rna_census').value = document.getElementById('census').value = document.getElementById('data').value = document.getElementById('data1').value = document.getElementById('data2').value = cur_census;
}
</script>
@tehoawebsite
Copy link

Hello! I was wondering if you could help me figure out/problem solve an issue I am having with using the "onkeyup". I have very little knowledge of coding and have been learning as I go through forums and support docs. Here is what I am hoping to achieve.

When a user goes to register and they are filling out the registration form. I would like the First Name field and the Last Name field information to automatically populate the Username field. I have done this with the following code...

<script type="text/javascript" charset="utf-8"> function updateUsername(){ first = document.getElementById("user_first_name-562").value; last = document.getElementById("user_last_name-562").value; document.getElementById("user_login-562").value = first+"-"+last; } </script>

However, I was unable to figure out where to put the "onkeyup" value for the different input fields without having them double populate. So I took the fields (user_first_name-562; user_last_name-562; user_login-562) and placed them in the registration template. I hide the username field so that the user would not be able to see it on the frontend.

My issue is this. One, is this the correct way to do this?? Two, the first name and last name fields do not autocomplete on the user page in wordpress. They are blank after a user registers. Any help you can provide would be very helpful! Thank you! I have attached the Registration.php template I am using for the form. The rest of the code that is not pictured is the same as the standard template.
2021-05-23

@vikramjeet-dev
Copy link
Author

hello @tehoawebsite first you have to create a function i have used name findPPD but you can use any function you want and using this keyword you can populate the value where u need .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment