Solved

website get element code - pull text from one page to next

Posted on 2011-02-20
5
745 Views
Last Modified: 2012-05-11
i want to be able to change text on one web page and have it change on another.

is there a way to do that using the GetElement javascript?

thanks
0
Comment
Question by:webdott
  • 2
  • 2
5 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 34939026
put the content in an hidden input or a cookie or as parameter in the url
0
 
LVL 15

Expert Comment

by:ludofulop
ID: 34939027
hi, sorry, it is not possible to do it using only javacript, you will need some server side scripting.

Only exception is if the pages are on the same domain, then you can use AJAX on second page to retrieve contents of the first page, and parse it using string functions or regular expressions, to get only the part you need
0
 

Author Comment

by:webdott
ID: 34939068
leakim971
can you give an example?

ludofulop
i use godaddy hosting which has AJAX as a feature.

the pages will be on the same domain, how would i do that with AJAX?

thanks
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34939128
The first page :
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	function passElement() {
		document.location.href = "page2bis.html?myelement=" + encodeURIComponent(document.getElementByid("me").innerHTML);
	}
</script>
</head>
<body>
	<form action="" method="get" onsubmit="passElement()">
        <div id="me">you want to put this content on the next page</div>
    	<input type="button" value="go to page2" />
    </form>
</body>
</html>

Open in new window


page2bis.html :

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

window.onload = function() {
   document.getElementById("metoo").innerHTML = gup("myelement");
}

</script>
</head>
<body>
<div id="metoo"></div>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:webdott
ID: 35052335
thank you

sorry for the delay. i thought i closed this out
with your answer a long time ago.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question