Label question

Discussion in 'JavaScript' started by mjliscio, Aug 9, 2007.

  1. #1
    Hello all, I have a quick question.

    I have the following javascript code Note the asp label at the end


    <script type = "text/javascript">
    function loadTest(VEMap1){
    alert("test");
    }// end zoom

    function endZoom(e)
    {

    alert(e.view.zoomLevel);

    document.getElementById(Label1).value = e.view.zoomLevel;


    }// end end zoom

    </script>

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    When my function endZoom is called I want Label1's text to change to e.view.zoomLevel. What am I doing wrong here

    Thanks Mike
     
    mjliscio, Aug 9, 2007 IP
  2. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Remove the "runat=server"

    You're attempting to use the label as if it were a static HTML element, but you can't do that with the runat=server.

    And you may have to use .innerHTML instead of .value
     
    Mike H., Aug 9, 2007 IP
  3. mjliscio

    mjliscio Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The problem with taking out the runat = "server" is that runat = "server" is required for the control is there any other way
     
    mjliscio, Aug 9, 2007 IP
  4. mjliscio

    mjliscio Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I solved my problem

    The correct code is

    <script type = "text/javascript">
    function loadTest(VEMap1){
    alert("test");
    }// end zoom

    function endZoom(e)
    {
    alert(e.view.zoomLevel);

    document.getElementById('<%=Label1.ClientID %>').innerText = e.view.zoomLevel;

    }// end end zoom

    </script>



    <asp:Label ID="Label1" runat = "server" Text="Label"></asp:Label>
     
    mjliscio, Aug 9, 2007 IP
  5. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes, use an ordinary <div id="swapDiv" style="display:none"></div>, using innerHTML to insert text, later.

    Use CSS, position.absolute to put the div above the Label.

    #swapDiv
    {
    position:absolute;
    top: 150px;
    left: 300px;
    }

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    Use JavaScript to, hide the Label, and display the div:

    document.getElementById('swapDiv').style.display = "";
    document.getElementById('Label1').style.display = "none";
    document.getElementById('swapDiv').innerHTML = "New Label Text";


    You can use JS to test which way you need to go:

    if (document.getElementById('swapDiv').style.display == "none")
    {
    document.getElementById('swapDiv').style.display = "";
    }

    Yes, the empty string is correct. Using an empty string to display elements ensures that it displays with its default property. A div is a block element. So, using "" ensures that it will display as expected, and not inline.

    A label is an inline element, but the same applies, use an empty string to display it, and "none" to hide it.
     
    Mike H., Aug 9, 2007 IP