Question: jsvalue is a simple implementation of the client that uses js to pass the default value.

Source: Internet
Author: User

Question: jsvalue is a simple implementation of the client that uses js to pass the default value.

The requirements and Code are as follows:

"This is my code :"

   1: <input type="text" id="price2" value="333"/>
   2: <input type="text" id="trueprice" value="" />
   3:
   4:
   5: <script type="text/javascript">
   6: document.getElementById("price2").onkeyup = function() {
   7: document.getElementById("trueprice").value = this.value;
   8: }
   9: </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:

   1: <!DOCTYPE HTML>
   2: 
   3:     
   4:         <meta http-equiv="content-type" content="text/html;charset=utf-8">
   5:         <title>Test</title>
   6:     
   7:     <body>
   8:    <input type="text" id="price2" value="333"  onkeyup="test(this.value);"/>
   9:    <input type="text" id="trueprice" value="" />
  10:     <script type="text/javascript">
  11:         var price2 = document.getElementById("price2").value;
  12:         document.getElementById("trueprice").value = price2;
  13:         function test (defaultVal) {
  14:           document.getElementById("trueprice").value = defaultVal;
  15:         }
  16:     </script>
  17:
  18:     </body>
  19: 

Effect:


The content entered in the first text box can be synchronized to the second text box.

 

If you have different opinions, please contact us. Sorry for the shortcomings.

Source: http://www.ido321.com/567.html

For setting the default parameter in js, You can stamp this: http://www.ido321.com/555.html




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.

In js, the default value of a user text box is 123. The password is also written by default. How can this problem be solved?

Value = "123" is to define an initial value.

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.