The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Is it possible to add some text inside DIV?
Nepal
post Sep 21 2010, 03:19 PM
Post #1





Group: Members
Posts: 6
Joined: 18-September 10
Member No.: 12,753



Hi All,

Is there anyway to insert some text inside <div> using javascript. I have 3 div with different in different location of page, i need to make one javascript function which can insert text into selected <div> Below is the example what i am looking for.
CODE



<script language="javascript">
function insertintodiv(var txt, var ddiv)
{
    if(ddiv == "div1")
            //INSERT INTO DIV1
    elseif (ddiv == "div2")
            // INSERT INTO DIV2
    else
            // INSERT INTO DIV3
    
}

</script>

</head>

<body>


    <DIV id = "div1" STYLE="position:absolute; top: 85px; left: 131px; width: 200px; height: 25px;">  </DIV>
     <DIV id = "div2" STYLE="position: absolute; top: 85px; left: 427px; width: 200px; height: 25px;">  </DIV>
      <DIV id = "div3" STYLE="position: absolute; top: 85px; left: 728px; width: 200px; height: 25px;">  </DIV>

  
  <!-------------------------------- Some dynamic action ---------------------------------->
  <script language="javascript">
  insertintodiv("Columns 1", "div1");
  insertintodiv("Columns 2", "div2");
   insertintodiv("Columns 3", "div3");
  </script>



It will be great help if i can find some similar way to finish my dynamic portal.

Thank You
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 21 2010, 04:04 PM
Post #2


.
********

Group: WDG Moderators
Posts: 8,444
Joined: 10-August 06
Member No.: 7



You can do it like this:

CODE
function insertintodiv(txt, ddiv)
{
    document.getElementById(ddiv).innerHTML=txt;
}


Note that "txt" and "ddiv" are function arguments (or parameters? unsure.gif ), not variables, so you can't write

CODE
function insertintodiv(var txt, var ddiv)


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Nepal
post Sep 22 2010, 05:26 AM
Post #3





Group: Members
Posts: 6
Joined: 18-September 10
Member No.: 12,753



Christian J,

Great working well.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Nepal
post Sep 22 2010, 08:28 AM
Post #4





Group: Members
Posts: 6
Joined: 18-September 10
Member No.: 12,753



I need one more info if possible please.

My all DIVs are under one table which have width 85%, i need to resize the div Left and top according to the table.

For the example if page resize the div must be set under the table. Currently my above given is ok if page is in normal mode but once it resize all div goes in different position.

I will appreciate for the hint.

Thank
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 22 2010, 12:36 PM
Post #5


.
********

Group: WDG Moderators
Posts: 8,444
Joined: 10-August 06
Member No.: 7



QUOTE(Nepal @ Sep 22 2010, 03:28 PM) *

My all DIVs are under one table which have width 85%, i need to resize the div Left and top according to the table.

First you should decide on a suitable HTML structure. Do you really need to use a table? If so, do you really need three DIV elements below that table (why not use three table cells instead)?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Nepal
post Sep 22 2010, 01:20 PM
Post #6





Group: Members
Posts: 6
Joined: 18-September 10
Member No.: 12,753



I am getting data from XML file and i need to set it on screen accordingly.

For the example here is the xml and how to display.

CODE

<grp1 columns="4">
    <row location="1" value="Display in Column 1" />
    <row location="3" value="Display in Column 3" />
    <row location="3" value="Display in Column 3" />
    <row location="2" value="Display in Column 2" />
</grp1>

<grp1 columns="5">
    <row location="1" value="Display in Column 1" />
    <row location="3" value="Display in Column 3" />
    <row location="3" value="Display in Column 3" />
    <row location="2" value="Display in Column 2" />
    <row location="5" value="Display in Column 5" />
</grp1>


When i start pulling the data i will make 4 or 5 DIVs according to the column value.
then i will start retrive the rows and put them in the same column where location has the value of target column number.

This is what i am trying to achive.

Please let me know if some code can do this job. it will really help me too much.

Thank You
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 22 2010, 02:23 PM
Post #7


.
********

Group: WDG Moderators
Posts: 8,444
Joined: 10-August 06
Member No.: 7



QUOTE(Nepal @ Sep 22 2010, 08:20 PM) *

I am getting data from XML file and i need to set it on screen accordingly.

Is this for an AJAX application? Otherwise server-side scripts are more reliable than client-side javascript.

In any case it sounds like tabular data, so you might consider displaying it in an HTML table on the web page. An HTML list might work too.

QUOTE
When i start pulling the data i will make 4 or 5 DIVs according to the column value.

This might complicate an HTML table structure, unless you always use 5 columns and sometimes leave one cell empty.

QUOTE
then i will start retrive the rows and put them in the same column where location has the value of target column number.

In your example the rows with location "3" share the same location/column. How is that supposed to work out? unsure.gif

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Nepal
post Sep 22 2010, 03:28 PM
Post #8





Group: Members
Posts: 6
Joined: 18-September 10
Member No.: 12,753



If possible in html table, how it can be?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 4th June 2020 - 09:47 AM