NaveenBhat
NaveenBhat

Reputation: 3318

Javascript change label's text via innerhtml not working

I have this javascript function:

function validateFile() {
            var file = document.getElementById('fuCSV');
            if (file.value == "") {
                document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "Please select a file to upload. Client!";
                return false;
            }
            else {
                document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "";
                return true;
            }
        }

Its called on the Button's OnClientClick event like this:

<asp:Button ID="btnImport" runat="server" Text="Import" OnClientClick="return validateFile();" CausesValidation = "true"
            UseSubmitBehavior ="true" OnClick="btnImport_Click" />

I'm trying to change the text of the label lblStatus on validateFile() method, but the text is not changing. However, while debugging...QuickWatch shows the changed value. What might be the cause for it? how can I resolve this?

Upvotes: 0

Views: 11193

Answers (4)

Mayur Nalwaya
Mayur Nalwaya

Reputation: 1

var e = document.getElementById("fName_err");
e.innerHTML = "** Enter first name";

get the id where you want to give output in e.

Upvotes: 0

Icarus
Icarus

Reputation: 63956

I had suggested to use innerText but apparently, the W3C-compliant way of doing this is to use textContent:

document.getElementById('<%=lblStatus.ClientID%>').textContent = "Please select a file to upload. Client!";

See Mozilla's documentation here.

Upvotes: 3

mamoo
mamoo

Reputation: 8166

Javascript is case sensitive, if you set innerhtml property instead of innerHTML you won't see anything.

Upvotes: 1

Niklas Wulff
Niklas Wulff

Reputation: 3524

Use correct casing on the property: innerHTML

http://www.tizag.com/javascriptT/javascript-innerHTML.php

Upvotes: 1

Related Questions