window.open location.href frame

Discussion in 'Javascript' started by Marcello, Nov 12, 2003.

  1. Marcello

    Marcello Guest

    Hello
    I have a page of 2 frame:
    menu (menu.php)
    corpo (corpo.php)

    In menu.php i have:
    <script>
    function selAut(){
    aut=autore.selectedIndex;
    aut=autore.options[aut].value;
    parent.corpo.location.href('http://www.laltrarete.it/mipiace/corpo.php?autore=aut');
    return true
    }
    </script>
    seleziona gli articoli per autore:
    <select name="autore" onsubmit="selAut()" target="corpo">

    But the browser try to open 'MENU.php?autore=aut'
    instead of
    CORPO.php?.....
    as i'd like.

    I tried even with
    window.open('http://www.laltrarete.it/mipiace/corpo.php?autore=aut',
    'corpo');
    but i got the same problem
    Any suggestion?
    thanks in advance
    and sorry for my bad english
    Marcello
    Marcello, Nov 12, 2003
    #1
    1. Advertising

  2. Marcello wrote:

    > I have a page of 2 frame:
    > menu (menu.php)
    > corpo (corpo.php)
    >
    > In menu.php i have:
    > <script>


    The `type' attribute is missing for valid HTML 4.

    > function selAut(){
    > aut=autore.selectedIndex;


    That variable is declared and defined global
    since the `var' keyword is missing. Bad style.

    > aut=autore.options[aut].value;


    The `autore' reference is defined nowhere. Only in some UAs like IE
    `identifier' automagically creates a reference to an element named
    `identifier', by document.all("identifier"). Pass a reference to the
    object explicitely instead. Since the method is invoked when the event
    fires for the object you access, the `this' operator and keyword serves
    the purpose.

    > parent.corpo.location.href('http://www.laltrarete.it/mipiace/corpo.php?autore=aut');


    location.href is a non-function property, i.e. no method.
    Downwards compatible is the assignment to `location' instead
    of to `location.href'.

    > return true
    > }
    > </script>
    > seleziona gli articoli per autore:
    > <select name="autore" onsubmit="selAut()" target="corpo">


    The `select' element has no (working) `onsubmit' event
    handler, the `form' element has. You were looking for

    <script type="text/javascript>
    function dummy(x)
    {
    return x;
    }

    function selAut(o)
    {
    if (!o
    || !o.options
    || !o.selectedIndex
    || o.selectedIndex < 0)
    return false;

    var aut = o.options[o.selectedIndex].value;

    /*
    * Define the method to convert the value
    * of the form element for a valid URI
    * Preference order is: encodeURIComponent,
    * escape, dummy.
    */
    var f =
    (typeof encodeURIComponent != "undefined"
    ? encodeURIComponent
    : (typeof escape != "undefined"
    ? escape
    : dummy));

    parent.corpo.location =
    'http://www.laltrarete.it/mipiace/corpo.php?autore='
    + f(aut);

    return true;
    }
    </script>

    <select name="autore" onchange="selAut(this)">

    and did not consider users with a keyboard whose navigation you make
    worse with this, for without special keys they can either select the
    first item only or have JavaScript disabled and miss the functionality
    you provided. Thus discard the `onchange' event handler and use
    `onsubmit' for the `form' element instead, also providing a server-side
    alternative with the `action' attribute for users without client-side
    JavaScript support where the event cannot be handled.

    BTW: Do not use tab characters in your code, their display depends on
    the client. Spaces (two recommended) will best serve the purpose of
    indentation.

    > But the browser try to open 'MENU.php?autore=aut'
    > instead of
    > CORPO.php?.....


    I hope you know that filenames on servers are case-sensitive in most
    cases.

    > I tried even with
    > window.open('http://www.laltrarete.it/mipiace/corpo.php?autore=aut',
    > 'corpo');


    This statement also misses the dynamic `aut' part. Unlike other script
    languages like PHP, variable identifiers are not automatically replaced
    by their value within string literals in JavaScript.

    > but i got the same problem


    BAD. Broken as designed.


    PointedEars
    Thomas 'PointedEars' Lahn, Nov 18, 2003
    #2
    1. Advertising

  3. Thank you very much, Thomas. It was a long and egsaustive
    help. Nevertheless, it seems it still doesn't work.
    At the moment my menu.php is



    <?php
    [omissis]
    foreach ($line as $col_value) {
    print "<td><a href=\"corpo.php?tema=$col_value\"
    target=\"corpo\">$col_value</a></td>\n";
    }
    print "\t</tr>\n";
    [omissis]
    ?>
    <div>
    <script type="text/javascript">
    function dummy(x){
    return x;
    }
    function selAut(o){
    if (!o
    || !o.options
    || !o.selectedIndex
    || o.selectedIndex < 0)
    return false;
    var aut = o.options[o.selectedIndex].value;
    var f =
    (typeof encodeURIComponent != "undefined"
    ? encodeURIComponent
    : (typeof escape != "undefined"
    ? escape
    : dummy));
    parent.corpo.location =
    'http://www.laltrarete.it/mipiace/corpo.php?autore='
    + f(aut);
    return true;
    }
    </script>

    <form action="" onsubmit="selAut(this)">
    seleziona gli articoli per autore:
    <select name="autore" >
    <?php
    $queryAutore=mysql_query("select username
    from autori");
    while
    ($line=mysql_fetch_row($queryAutore){
    foreach ($line as $autore) {
    print ("<option name=\"autore\"
    value=\"$autore\">$autore</option>"); }
    }
    ?>
    </select>
    <input type=submit value="seleziona" >
    </form>
    [omissis]

    but the problem is the same : the query string is passed but the url
    passed is bad menu.php insteead of corpo.php
    (upper case in the previous message was mine, just for emphasis).

    >also providing a server-side
    >alternative with the `action' attribute

    yes but how can i do that?
    The first line of code above is only based on php,
    but here i need some more compact (as a select) , in order to make the
    page shorter.
    Thank you again and sorry for my bad english
    Marcello

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Marcello Console, Nov 18, 2003
    #3
  4. Marcello Console wrote:

    > Thank you very much, Thomas.


    You are welcome.

    > It was a long and egsaustive help. Nevertheless, it seems it
    > still doesn't work.


    The main problem is that you do not call the method correctly
    because you have not understood what it is doing exactly. You
    should read more on JavaScript and DOM(s) before you continue
    programming.

    > At the moment my menu.php is
    >
    >
    >
    > <?php


    Server-side script code is not useful for analyzing its client-side
    consequences. Post what the client gets instead, *after* the PHP
    Hypertext Preprocessor has replaced it.

    > [...]
    > <form action="" onsubmit="selAut(this)">


    selAut(...), as it was rewritten by me, requires a reference to an
    HTMLSelectElement object, not a HTMLFormElement object, as first
    argument. So it must fail on

    | if (!o
    | || !o.options

    here because an HTMLFormElement object referenced in the event handler of
    the *form* element with `this' does not have a `options' property which
    causes the `if' statement to evaluate to `true' and

    | return false;

    to execute with which the function is left.

    Thus you need to use this.elements['autore'] instead of `this' *there*.

    > (upper case in the previous message was mine, just for emphasis).


    Better to use *bold*, /italic/ and/or _underlined_ instead. Good
    NetNews clients even format the text on display as described above.

    >> also providing a server-side alternative with the `action' attribute

    >
    > yes but how can i do that?


    <form action="alternative.php" ... onsubmit="return selAut(this)" ...>

    The event fires when the user clicks the submit button of the form and if
    client-side JavaScript is supported it is then handled.[1] Because the
    return value of the method is returned to the event handler, it is possible
    to cancel the submit event, meaning that the UA will continue as if the
    submit button was not pushed in the first place and thus ignoring the
    `action' attribute. So either the method returns `false' always (currently
    it only returns `false' on failure) or you leave it as is and use

    <form
    action="alternative.php"
    ...
    onsubmit="selAut(this); return false;"
    ...
    >


    instead.

    In either case, without JavaScript the UA will ignore the event handler and
    use the `action' attribute to access a resource that is passed the input
    data. You then can also use the `target' attribute to specify the name of
    the window where the submit result should be displayed.

    Maybe you already know the following:

    There are two request methods available: GET and POST. GET, which is the
    default, appends the data to the URI of the resource to be accessed like
    `?name=value&name2=value2...'.[2] With POST, defined by `method="post"
    for a `form' element, the URI remains unchanged but the form data is
    included in the body of the HTTP request. Because of that, the latter is
    suited for the transmission of extensive and/or sensitive information (the
    submitted data is not stored in the history of the user as URL and the
    limitations of length UAs and servers impose on URIs do not apply.) Having
    PHP available, you can retrieve either information by the $_GET and $_POST
    superglobal arrays, the $HTTP_GET_VARS and $HTTP_POST_VARS arrays or, with
    the discouraged register_globals=on even with $name. (See the PHP manual for
    details.)


    HTH

    PointedEars
    ___________
    [1]
    Define the default scripting language used for event handler code with

    <meta http-equiv="Content-Script-Type" content="text/javascript">

    within the `head' element.


    [2]
    Note that with JavaScript manipulating the `location' property, GET is used,
    too. To let the UA perform a POST request initiated by JavaScript code, you
    need either need to call the submit() method of a POST form after
    manipulating its data or use advanced techniques like e.g. XMLHTTPRequest.
    Google is your friend. [psf 6.1]
    Thomas 'PointedEars' Lahn, Nov 18, 2003
    #4
  5. As i don't see my reply, i post it again.
    Sorry if it is a deja-view for you.
    >Server-side script code is not useful for ...

    yes i know, but imput that rows in order to make more clear what i
    whanted to do.

    >selAut(...), as it was rewritten by me, requires a >reference to an

    HTMLSelectElement object, ....
    yes, it solved . What make me confused is that on the bwoser appeared
    menu.php?autore=...., with exact(fit) query string, even if only for a
    piece of second. So i investigate on bad url , instead of wrong passing
    of parameter. Even now , i can see ...menu.php?autore...... Isn't it
    strange?



    >>also providing a server-side alternative with the `action' >>

    attribute
    > yes but how can i do that?
    >> <form action="alternative.php" ... onsubmit="return >selAut(this)"

    ...>

    I know i could put corpo.php?autore=$aut in the action, but what i don't
    know is to pass 'target="corpo"' (corpo is the frame). If i'd known , i
    wouldn't use javascript.

    > You should read more on JavaScript and DOM(s) before you >continue

    programming.
    Sure i must study js. But now i'm studing php, i just needed this for go
    ahead. As for DOM, isn't it only for ms iexplorer?

    Thank you again
    Marcello

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Marcello Console, Nov 20, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon
    Replies:
    1
    Views:
    10,176
    Boban Dragojlovic
    Jun 24, 2003
  2. saiho.yuen
    Replies:
    3
    Views:
    411
    kaeli
    Sep 14, 2004
  3. Replies:
    2
    Views:
    444
  4. John
    Replies:
    2
    Views:
    364
  5. Alex Bird
    Replies:
    3
    Views:
    170
    Thomas 'PointedEars' Lahn
    May 9, 2008
Loading...

Share This Page