How can I mantain the OPENER state?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

How can I mantain the OPENER state?

Post by Jaxolotl »

Hi everyone
Even if I 'm a PHP programmer I'm a newbie in Javascript (shame on me :oops: )
I allways C/P Javascript an this is my first "step" writing.

The problem
I create two pages that should be connected with javascript in this way.
The page 1.html contains two input text fields with the unique ID and a link that through javascript opens the page 2.php passing the ID of the text field I want to fill.

The file 2.php contains many values, onClick the send the selected value to 1.html and to the wright field.
This works fine if I make no action inside 2.php but if for example I do a POST or a link action inside 2.php the reference to 1.html and the field ID get lost.

How can I do to mantain those values even if I move around the 2.php page?
Am I taking the wrong road to success? LOL
is it a concept problem or procedure problem?
TNX for your time

1.html code

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>

<script language="JavaScript" type="text/JavaScript">
	<!--
	function open_tool(URL,field_identifier){
	win2=window.open(URL,"","scrollbars=yes,width=700,height=500");
	win2.creator=self;
	win2.field_identifier=field_identifier;
	}
	//-->
</script>
</head>
<body>
	
	<form  action="" method="POST">
	<input type="text" name="title" id="title" value=""><a href="javascript:open_tool('2.php','title');" >()</a><br>
	<input type="text" name="color" id="color" value=""><a href="javascript:open_tool('2.php','color');" >()</a>
</form>
</body>
</html>
2.php code

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Untitled Document</title>
		<script language="JavaScript" type="text/JavaScript">
			<!--
			function return_tool_selection(field_identifier_value){
				window.opener.document.getElementById(field_identifier).value=field_identifier_value;
			}
			//-->
		</script>
	</head>

	<body>
		<ul>
			<li><a href="<?php echo $_SERVER['PHP_SELF']."?listing=blue_line"; ?>">Blue Line</a></li>
			<li><a href="<?php echo $_SERVER['PHP_SELF']."?listing=red_line"; ?>">Red Line</a></li>
		</ul>
		<table cellpadding="2" cellspacing="0" border="0" width="300">
			<?php
			if($_REQUEST['listing'] == "blue_line"){
				?>
				<tr>
					<td colspan="2">
						Blue line
					</td>
				</tr>
				<tr>
					<td bgcolor="#006388">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#006388');window.close();">#006388</a></td>
				</tr>
				<tr>
					<td bgcolor="#0094CC">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#0094CC');window.close();">#0094CC</a></td>
				</tr>
				<tr>
					<td bgcolor="#0DBCFF">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#0DBCFF');window.close();">#0DBCFF</a></td>
				</tr>
				<?php
			}
			elseif($_REQUEST['listing'] == "red_line"){
				?>
				<tr>
					<td colspan="2">
						Red Line
					</td>
				</tr>
				<tr>
					<td bgcolor="#7D0003">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#7D0003');window.close();">#7D0003</a></td>
				</tr>
				<tr>
					<td bgcolor="#B00004">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#B00004');window.close();">#B00004</a></td>
				</tr>
				<tr>
					<td bgcolor="#F00006">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#F00006');window.close();">#F00006</a></td>
				</tr>
				<?php
			}
			else{
				echo "<tr>
				<td colspan=\"2\">
				Select a list
				</td>
				</tr>";
			}
			?>
		</table>
	<br><br><br><br>	
		
		<table cellpadding="2" cellspacing="0" border="0" width="300">
				<tr>
					<td colspan="2">
						Fixed Line
					</td>
				</tr>
				<tr>
					<td bgcolor="#0C5900">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#0C5900');window.close();">#0C5900</a></td>
				</tr>
				<tr>
					<td bgcolor="#118800">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#118800');window.close();">#118800</a></td>
				</tr>
				<tr>
					<td bgcolor="#17B900">&nbsp</td>
					<td><a href="javascript:return_tool_selection('#17B900');window.close();">#17B900</a></td>
				</tr>

		</table>
	</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You could inject the data into the URL being accessed.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Recommendation not solution: Don't use pop-up windows such as window.open, anyone who follows web standards based design will frowned upon such things. Also if you stay within the one browser window you should be able to do what you need with PHP by generating and reading the GET query string, which is good because it'll work without JavaScript then :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I think I would put 1.html (the one with all the values) in a frame. Then have 1.html communicate with it parent and the parent page open and communicate with 2.php.
(#10850)
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

Post by Jaxolotl »

feyd wrote:You could inject the data into the URL being accessed.
I had the same idea, but the only result I get was to pass the "field_identifier" (the field ID) by URL reference the mantain it and passing it by $_REQUEST even if use links or POST forms inside the page. But I don't know where to start to mantain the OPENER reference, just don't know how to access it (the var) or to inject it when done.
Is just like knowing the exact word in English, Italian or Spanish to explain a concept but just don't know how to say it in Korean.
ole wrote:Don't use pop-up windows such as window.open, anyone who follows web standards based design will frowned upon such things
Have no problems to do it without javascript or popup, but some clients Love their POPUPS and as you can see when posting here the left part of the "Post a reply" box has a popup link to open the complete Emoticon set., and if you read the code you'll find

Code: Select all

<script language="javascript" type="text/javascript">
<!--
function emoticon(text) {
	text = ' ' + text + ' ';
	if (opener.document.forms['post'].message.createTextRange && opener.document.forms['post'].message.caretPos) {
		var caretPos = opener.document.forms['post'].message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		opener.document.forms['post'].message.focus();
	} else {
	opener.document.forms['post'].message.value  += text;
	opener.document.forms['post'].message.focus();
	}
}
//-->
</script>
sometimes is very "comfortable" to use a popup instead of reload the page (unless you use AJAX but this is not my case)
Maybe I should RT*M, all of it..... anyway if someone has an idea I will appreciate it very much


by the way ... I prefer to stay on W3C compliant and web standards code but sometimes it takes much time to do it correctly....what if the client doesn't want to pay for the extra time? I take all the time I need to be satified when projecting for myself but you'll be amazed about how many times clients fight to defend their "self-destructive" position even if you explain clearly that this desition will harm their bussines. For example developing the service site completly in flash without any "HTML" output or alternative site to be spidered, with the Logo designed by the daughter and the pictures of the office shoted by the son and maybe the Ludwig van Beethoven's 5th symphony (all of it) in streaming on an ADSL connected server ........... and we have to pay the rent because we expend too much money this month or want the new gigabit hardware!!!!!!......so you'd better learn an alternative way to do that as fast as you can and keep it out of your portfolio.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

OK its good that are you are familiar with web standards. I take your point about time and clients - Don't stop trying to educate each client you have but if you can't be bothered with the resistant ones, well, I'm certainly not blaming you.

I work in a bit of a ideal world when it comes to web design because I spend all my time working either on personal projects or for my one, very nice, client. As my client likes the higher end stuff he's interested in quality and thus web standards.
so you'd better learn an alternative way to do that as fast as you can and keep it out of your portfolio.
I can't wait for the day that someone makes a really good WYSIWYG HTML/CSS editor. Till then, I just learn to do it faster and faster myself. I don't even know if any other way is faster.

Sorry I can't help you with your pop-up problem as I never use them :)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

http://developer.mozilla.org/en/docs/DOM:window.opener

main window:
there's a form here
a form control spawns a new popup window via window.open()

popup window:
over in the popup window, you have a new form where the user inputs something for processing
the form is submitted, processing occurs on the server in PHP
resulting page has the desired information contained in an element
the popup moves this data to the parent window:

Code: Select all

window.opener.document.getElementById('someElement').value = document.getElementById('anotherElement');
or something like that...
then you can close the popup window with self.close()


Is that what you're looking for?
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

Post by Jaxolotl »

Oh thanks for your replys & time people!
I didn't access the forum this days

I'll try this solution and if it works (or I implement it wright :oops: ) I'll post it here
Post Reply