?
Solved

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

Posted on 2011-02-20
5
Medium Priority
?
758 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Suggested Courses

800 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