Sample Code that uses js to pass the default value, and jsvalue sample code
The requirements and Code are as follows:
"This is my code :"
<input type="text" id="price2" value="333"/><input type="text" id="trueprice" value="" />
<script type="text/javascript">document.getElementById("price2").onkeyup = function() {document.getElementById("trueprice").value = this.value;}</script>
Q: When you open this page, the value of trueprice is empty by default. How can we achieve the default value of trueprice on this page, which is already the same as price2? (Price2 is a dynamic value)
<Input type = "text" id = "trueprice" value = ""/> is fixed and cannot be modified.
One of my simple implementations:
<!DOCTYPE HTML>
Effect:
The content entered in the first text box can be synchronized to the second text box.
How to Use JS to pass the DIV form value to the input form value
Add an ID to input, for example, id = "mypwd"
Direct assignment:
Document. getElementById ('mypwd'). value = document. getElementById ('iddiv _ PWD_PasswordExample '). innerHTML;
How to Use JS to retain the value after the submitted Form
In this case, the submission action will be postback to the background for processing, right. After the page is refreshed, NO content is found in the text box.
There are two solutions to this problem:
1. Use the background code: server code variables to save these values. For example, c.
<Input type = "text" value = "<% = entity. time %>" id = "date"/>
Assign a value to the entity object before submitting the object, so that the object can be saved.
2. Page backfilling:
Session Storage is just an example.
Before submission, save the text box content on the page to global variables, such as session Storage. Every time js runs in window. onload, it determines whether there is a value in [session Storage], and then it will be refilled.
3. Some frameworks on the market support page backfilling. You can look for it.