Get a DIVs innerhtml value into a textbox?

Last post 07-21-2009 12:06 PM by haku. 4 replies.

Sort Posts:

  • Get a DIVs innerhtml value into a textbox?

    07-21-2009, 11:38 AM
    • Member
      197 point Member
    • blink18jew
    • Member since 05-22-2007, 12:12 AM
    • Posts 626

    Hey, is there a way of (using Javascript) getting a DIVs innerhtml value into a textbox. i have tried : 

      document.getElementById('txtBox').value = document.getElementById('divvalue').innerHTML;

    and

    document.getElementById('<%=_txtBox.ClientID%>') = document.getElementById('divvalue').innerHTML; 

    i am refernancing some javascript files at the top of the page, would this be getting in the way? This is driving me insane! I dont mind if the DIVs value needs to be put into a label insted of a textbox, thanks Si 

  • Re: Get a DIVs innerhtml value into a textbox?

    07-21-2009, 11:47 AM
    • Participant
      1,074 point Participant
    • klpatil
    • Member since 09-02-2008, 9:24 AM
    • Vadodara
    • Posts 206

    hi,

    Sorry, I am not able to undestand what is your question. Can you please elaborate it further?


    Let me know if you need further assistance. I will be happy to help you.

    HTH

    -Kiran
    For more solution like this my blog is here
  • Re: Get a DIVs innerhtml value into a textbox?

    07-21-2009, 11:55 AM
    • Member
      197 point Member
    • blink18jew
    • Member since 05-22-2007, 12:12 AM
    • Posts 626

     hey, i have a DIV :

    <div id="div1"></div>

    which on page load gets a dynamic value, i want to put that value into a .net textbox (or label). Thanks Si

  • Re: Get a DIVs innerhtml value into a textbox?

    07-21-2009, 12:00 PM
    • Participant
      1,387 point Participant
    • haku
    • Member since 07-15-2009, 6:17 AM
    • Posts 237

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <div id ="divvalue">Ola senor....</div>
            
            <asp:TextBox ID="txtBox" runat="server"></asp:TextBox>
            
            <script language=javascript>
                document.getElementById('txtBox').value = document.getElementById('divvalue').innerHTML;
            </script>
            
        </div>
        </form>
    </body>
    </html>


     

     

    Please Mark as Answer if the post helps you.
  • Re: Get a DIVs innerhtml value into a textbox?

    07-21-2009, 12:06 PM
    • Participant
      1,387 point Participant
    • haku
    • Member since 07-15-2009, 6:17 AM
    • Posts 237

     You can do that on server side :

    RegisterStartupScript("MyScript", "<script language=javascript>document.getElementById('" + txtBox.ClientID + "').value = document.getElementById('divvalue').innerHTML;</script>");


     

    I think that the mistake you have made is to put your script before the textbo.

    When page load , javascript try to execute the code by do not know yet the textbox control and the div.

    To be sure that a javascript is executed when all your page is loaded (or DOM built) add defer="defer" on javascript tag

    <script language=javascript defer=defer>

     

    Please Mark as Answer if the post helps you.
Page 1 of 1 (5 items)