nouman arshad
nouman arshad

Reputation: 463

javascript Cannot read property 'style' of null

 function showNotes() {

     var ThemeValues = "<%=str3%>"
     if (ThemeValues.value == "MyCity-Social") {

         document.getElementById("TextBox1").style.visibility = "visible";
         document.getElementById("TextBox2").style.visibility = "visible";
         $.blockUI({
             message: $('#divNotes'),
             css: {}
         });
     } else {

         //ERROR
         document.getElementById("TextBox1").style.display = "none";
         document.getElementById("TextBox2").style.display = "none";

         $.blockUI({
             message: $('#divNotes'),
             css: {}
         });

     }
 }

function is declared at top and called on click but error is above desribed and also var ThemeValues do not show value

Upvotes: 0

Views: 869

Answers (2)

martinlabs
martinlabs

Reputation: 1032

add ClientIDMode="Static" on your textbox control

<asp:TextBox ID="TextBox1" runat="server" Width="385px" Height="50px" TextMode="MultiLine" ClientIDMode="Static"></asp:TextBox>

And then your code above will works.

And for ThemeValues variable there, you won't get a any control value there, because you only assign a string to variable there.

use this instead

var ThemeValues = document.document.getElementById("<%=str3%>");

Upvotes: 1

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

use like this

document.getElementById('<%= TextBox1.ClientID%>').style.display = "none"

instead of

document.getElementById("TextBox1").style.display = "none";

Upvotes: 1

Related Questions