I need help with java script codeing

james70

New Member
Messages
7
Reaction score
0
Points
0
I want to extract some info from one page and insert it into another page.

I have a section of a page that looks like this:

HTML:
  <!-- start content -->
  <div id="content">
   <div class="post">
    <h1 class="title"><p>Title</p></h1>
    <div class="entry">
          My Text........
    </div
   </div>
  </div>
  <!-- end content -->

How do I extract and write the " My Text......" to another page?
 
Last edited by a moderator:

ellescuba27

Member
Messages
273
Reaction score
3
Points
18
Hi james70!
There are a few ways to pass the information to the other page, I am assuming that's what you want.
First, we want to get what's inside that <div>. I would do this by giving the <div> an ID:
HTML:
<div id="texttoget" class="entry">
My Text...
</div>
And with Javascript, get the text inside using innerHTML. Let's put it in a variable called thetext .
Code:
var thetext = document.getElementById("texttoget").innerHTML;

Now we decide how to pass it. My personal favourite is using window.name .
Code:
window.name = thetext;
That way the window's name will be what is inside the <div>. When you get to the other page, just use
Code:
var thetext2 = window.name;
Now the other page has what was in that <div> in the variable thetext2 . Make sure you clear window.name though (the default is "view").

Another way to do it is to use the address bar at the top of the page. There is a tutorial on how to do this at HTMLGoodies (he'll probably explain it better):
http://www.htmlgoodies.com/beyond/j...k-Tutorial-on-JavaScript-Variable-Passing.htm

So now you know! Hope that helps!
 
Last edited by a moderator:

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
I added [html] and [code] tags to both of your posts - please use them in the future.

Adding it to the window object will not mean that you can access it across pages, you want to set a cookie or something.


I'm not really sure what you're asking - could you give us a context and example, please? Also, are you using AJAX at all?
 
Top