简体   繁体   中英

Encoded value is displaying on textbox :- encodeURIComponent()

I'm calling a javascript function on OnClientClick of my button control to encode a textbox value .
That JS function calls encodeURIComponent() to encode the text value of textbox.

My Javascript function is

function Validate() {
    var d = document.getElementById('<%=NoteText.ClientID %>');
    var Hdn = document.getElementById('HdnProcessing');
    if (d.value == '') {
        alert(document.getElementById('<%=NotesMessage.ClientID %>').value);
        d.focus();
        return false;
    }
    if (Hdn.value == "Processing") {
        return false;
    } else {
        Hdn.value = "Processing";
        var headObj = document.getElementById('<%=NoteHeading.ClientID %>');
        headObj.value = encodeURIComponent(headObj.value);
        d.value = encodeURIComponent(d.value);
        return true;
    }
}

Here my inputs are textboxes ie NoteText and NoteHeading.

If anyone is reading this I was wondering is there anyway to pass the encoded text to the server without the user seeing the encoded text updating in the textbox. Currently when the user clicks the SAVE button they see the text change to the encoded text for a split second before the page refreshes. I was just curious if I could prevent the user from seeing that.

I recently provided an answer to a very similar question that should help you out:

JavaScript encode field without spoiling the display

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