Sample Code that uses js to pass the default value, and jsvalue sample code

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.