Jump to content

Refresh page


killboy

Recommended Posts

Okay, I don't really know where to put this thread. I think that this trick is made in JavaScript.I have a form working with PHP and as usual, you fill the blank fields and stuff.The thing is that I have a SELECT list with various options; if the option is not listed, there's always a last option called "Other", where you just click and open a new window, which has a new form and you just fill it with the name of the new element and a lil description.What I need is that, after you register this new element and close the window, the main page get refreshed with the new Option on it and without losing any of the other data.I know it is possible, becuz I've seen implemented in this forums.So, how can it be done??Thanks.

Link to comment
Share on other sites

You can use the parent object to access functions and things on the parent page. The opener object might also be useful. If you have a page with this Javascript function, which you can use to add your element:function test_func(a, B){...}If that page opens a popup window, when you are done in the popup window you can call the function in the opener to send your data to the other page.window.opener.test_func(var1, var2);To see an example, save this as js-comm.html:

<html>  <head>	<title>JS Communication</title>	<script type="text/javascript">	function open_win()	{	  window.open("js-comm2.html", "_blank", "width=400,height=300");	}	function test_func()	{	  document.getElementById("feedback").innerHTML = "This content was written using test_func";	}	</script>  </head>  <body>	<a href="javascript:void(0);" onclick="open_win()">Click</a>	<div id="feedback"></div>  </body></html>

And this as js-comm2.html:

<html>  <head>	<title>JS Communication</title>	<script type="text/javascript">	function test_comm1()	{	  window.opener.document.getElementById("feedback").innerHTML = "This was written from the popup window";	}	function test_comm2()	{	  window.opener.test_func();	}	</script>  </head>  <body>	<a href="javascript:void(0);" onclick="test_comm1()">Test 1</a><br>	<a href="javascript:void(0);" onclick="test_comm2()">Test 2</a>  </body></html>

Link to comment
Share on other sites

java script:void(0) does nothing as the function name suggests the following link explains it in some more detail. http://www.tizag.com/javascriptT/javascriptvoid.phpinnerHTML is a property of a DOM object which contains, you guessed it, the HTML inside the object/element you are accessing. Take this for example.HTML

<div id="outer">	<div id="inner">		Inner container!	</div></div>

JavaScript

var outer = document.getElementById('outer');var inner = document.getElementById('inner');alert(outer.innerHTML); // => <div id="inner">Inner container!</div>alert(inner.innerHTML); // => Inner container!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...