简体   繁体   中英

keep submitted values of a label text on radio button click with JQuery, C#

I Have the JQuery code following under to change text label values in a formulary. But on submit them(if have an invalid filled field), the text label values returns of the original value. How can i keep these values for not fill the fields again?

<script type="text/javascript">

    $(document).ready(function () {
        $('input:radio').change(function () {
            var rbvalue = $('input:radio:checked').val();
            if (rbvalue === "D") {
                $('#idCard').html('IC:');
                $('#userName').html('User Name: ');
                $('#completeName').html('Complete Name: ');
                $('#userAdress').html('User Adress: ');
            }
            else if (rbvalue === "B") {
                $('#publicId').html('Public Identificator: ');
                $('#publicName').html('Public Name: ');
                $('#publicCompleteName').html('Public Complete Name: ');
                $('#publicAdress').html('Public Adress: ');
            }

        });
    }); 
</script>

You can:

  1. Write a server-side routine that changes the label text so the page will render correctly after postback.
  2. Store the client-side labels in a hidden field before form submission and then use JavaScript to restore the labels after postback.
  3. Use an AJAX call to check values prior to actual form submission and prevent the form from being submitted if the values are incorrect.
  4. Do entirely client-side validation and prevent the form from being submitted if the values are incorrect.

Or any combination of the above.

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