...

View Full Version : Resolved changing parent.location.href changes current page instead



jlustgar
02-26-2012, 02:10 AM
hi,
have a series of 2 pages. The first is a drop down select box that gathers the state name. Onclick we are using a window.open to open a page with a list of cities for that state. Again using a drop down select box to select the city and then, onclick, we send the user off to the appropriate page based on state/city selection while at the same time updating the 1st (parent) page with a new location.href.

Problem is that instead of updating the parent page, it updates the page with the list of cities (the child page).

On the first page script we generate the following warning:

Warning: XUL box for _moz_generated_content_after element contained an inline #text child, forcing all its children to be wrapped in a block.
Source File: chrome://browser/content/browser.xul
Line: 0

First page is not generated via javascript but standard html. This happens both locally and when pages are moved to the server (Apache).

First page script is as follows

<HTML>
<HEAD>
<TITLE>J1</TITLE>

<SCRIPT LANGUAGE="JavaScript">
function StateSelect (form) {
Item = form.state.selectedIndex;
Result = form.state.options[Item].value;
window.open('j2.htm?value='+ Result,'myWindow','resizeable=no,resizeable=0,scrollbars=no,scrollbars=0,location=no,location=0,tool bar=no,toolbar=0,directories=no,directories=0,menubar=no,menubar=0,status=no,status=0,copyhistory=no ,copyhistory=0,width=300,height=100,left=300,top=300,screenX=300,screenY=300')
}
</SCRIPT>
</HEAD>

2nd page (where user selects city) code is as follows:

<SCRIPT LANGUAGE="JavaScript">
function CitySelect (form) {
Item = form.city.selectedIndex;
city = form.city.options[Item].value;
state = document.myform.state.value;
window.open('j3.htm','mywindow3')
setTimeout("Func1()",3000);
}

function Func1()
{
parent.location.href='j4.htm?st='+ state + '&city=' + city,'mywinow2';
}
</SCRIPT>

Ideas on why and what the error (actually a warning) is trying to tell us?

Thank you all!
Jim

DanInMa
02-26-2012, 05:16 AM
the error you mention is pointing to some kind of layout problem, and youre only showing part of the code for your page.please show the entire code for the first page so we can see how you are calling the function, etc...
oh also have you tried testing in another browser other than firefox( all the hits i got for the error are on mozilla support pages)

oh and also, the language property is deprecated, you should use type="text/javascript", jsut fyi.

- one more thing, there are actually easier ways to do what your trying to accomplish. one would be adapting the current concept to use an iframe instead of a new window, the other would be using an array to populate new dropdowns based on user selections - http://bonrouge.com/~chain_select_js

or ajax if you want to store all the info in a database - http://bonrouge.com/~chain_select_ajax

jlustgar
02-26-2012, 08:02 AM
Hi,
Thanks for the reply.

I used "text/javascript" on page 1 but the script then refuses to run. No error in firefox but IE give an error on Line 25, char 1 saying 'Object expected'.

I'm including the entire page. As you'll notice, I've condensed the form to ease in troubleshooting (including hardcoding the state name on page 2.

Page 1 entire html code:


<HTML>
<HEAD>
<TITLE>J1</TITLE>

<SCRIPT LANGUAGE="javascript">
function StateSelect (form) {
Item = form.state.selectedIndex;
Result = form.state.options[Item].value;
window.open('j2.htm?value='+ Result,'myWindow','resizeable=no,resizeable=0,scrollbars=no,scrollbars=0,location=no,location=0,tool bar=no,toolbar=0,directories=no,directories=0,menubar=no,menubar=0,status=no,status=0,copyhistory=no ,copyhistory=0,width=300,height=100,left=300,top=300,screenX=300,screenY=300')
}
</SCRIPT>


</HEAD>
<body>

<form name="myform" action="" target="_blank" method="get">
<FONT FACE="Verdana,Arial,Helvetica" SIZE="2">Select a state<br>
<select name="state">

<option value="A" >A</option>
<option value="B" >B</option>

</select>
<INPUT TYPE="button" NAME="button" Value="go" onClick="StateSelect(this.form)">
</FORM>
</body></html>


Page 2 (where you would select a city) is:


<HTML>
<HEAD>
<TITLE>J2</TITLE>

<SCRIPT LANGUAGE="JavaScript">
function CitySelect (form) {
Item = form.city.selectedIndex;
city = form.city.options[Item].value;
state = document.myform.state.value;
window.open('j3.htm','mywindow3')
setTimeout("Func1()",3000);
}

function Func1()
{
parent.location.href='j4.htm?st='+ state + '&city=' + city,'mywinow2';
}
</SCRIPT>

</HEAD>
<body>
This is J2

<form name="myform" action="" method="get">

<input type="hidden" name="state" value="NE">

<FONT FACE="Verdana,Arial,Helvetica" SIZE="2">Select a state<br>
<select name="city">
<option value="1" >1
<option value="2" >2
</select>

<INPUT TYPE="button" NAME="button" Value="go" onClick="CitySelect(this.form)">
</FORM>

</body></html>


thanks all...

felgall
02-26-2012, 08:16 AM
The script is refusing to run because you are using really old constructs that modern browsers don't support. The most recent browser that I would expect to understand that code properly would be Netscape 4. Looks like the HTML you are using was obsolete in 1997 as well.

You'd have better luck getting the code to work if you were to write it the way modern browsers expect instead of targetting Netscape 2.

Also when one window is opened from another in JavaScript the one that is opened can reference the one that opened it using opener - you only use parent when there are frames.

jlustgar
02-26-2012, 09:20 AM
felgall,
many thanks, that was it (opener, not parent).

as you noticed, my skills are way out of date. still not bad for someone who started on punch cards (oh, those were the days).

again, my warm appreciation.

have a g'day mate!

cheers,
jim



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum