Solved

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

Posted on 2011-02-20
5
729 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
Comment Utility
put the content in an hidden input or a cookie or as parameter in the url
0
 
LVL 15

Expert Comment

by:ludofulop
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now