Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    changing parent.location.href changes current page instead

    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
    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,toolbar=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:
    Code:
    <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
    Last edited by jlustgar; 02-26-2012 at 08:26 AM.

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    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
    Last edited by DanInMa; 02-26-2012 at 04:25 AM.

  • Users who have thanked DanInMa for this post:

    jlustgar (02-26-2012)

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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:
    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,toolbar=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:
    Code:
    <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...

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    jlustgar (02-26-2012)

  • #5
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •