window.open location.href frame

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcello

    window.open location.href frame

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

    In menu.php i have:
    <script>
    function selAut(){
    aut=autore.sele ctedIndex;
    aut=autore.opti ons[aut].value;
    parent.corpo.lo cation.href('ht tp://www.laltrarete. it/mipiace/corpo.php?autor e=aut');
    return true
    }
    </script>
    seleziona gli articoli per autore:
    <select name="autore" onsubmit="selAu t()" target="corpo">

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

    I tried even with
    window.open('ht tp://www.laltrarete. it/mipiace/corpo.php?autor e=aut',
    'corpo');
    but i got the same problem
    Any suggestion?
    thanks in advance
    and sorry for my bad english
    Marcello
  • Thomas 'PointedEars' Lahn

    #2
    Re: window.open location.href frame

    Marcello wrote:
    [color=blue]
    > I have a page of 2 frame:
    > menu (menu.php)
    > corpo (corpo.php)
    >
    > In menu.php i have:
    > <script>[/color]

    The `type' attribute is missing for valid HTML 4.
    [color=blue]
    > function selAut(){
    > aut=autore.sele ctedIndex;[/color]

    That variable is declared and defined global
    since the `var' keyword is missing. Bad style.
    [color=blue]
    > aut=autore.opti ons[aut].value;[/color]

    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("i dentifier"). 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.
    [color=blue]
    > parent.corpo.lo cation.href('ht tp://www.laltrarete. it/mipiace/corpo.php?autor e=aut');[/color]

    location.href is a non-function property, i.e. no method.
    Downwards compatible is the assignment to `location' instead
    of to `location.href' .
    [color=blue]
    > return true
    > }
    > </script>
    > seleziona gli articoli per autore:
    > <select name="autore" onsubmit="selAu t()" target="corpo">[/color]

    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.selectedInde x
    || 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: encodeURICompon ent,
    * escape, dummy.
    */
    var f =
    (typeof encodeURICompon ent != "undefined"
    ? encodeURICompon ent
    : (typeof escape != "undefined"
    ? escape
    : dummy));

    parent.corpo.lo cation =
    'http://www.laltrarete. it/mipiace/corpo.php?autor e='
    + f(aut);

    return true;
    }
    </script>

    <select name="autore" onchange="selAu t(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.
    [color=blue]
    > But the browser try to open 'MENU.php?autor e=aut'
    > instead of
    > CORPO.php?.....[/color]

    I hope you know that filenames on servers are case-sensitive in most
    cases.
    [color=blue]
    > I tried even with
    > window.open('ht tp://www.laltrarete. it/mipiace/corpo.php?autor e=aut',
    > 'corpo');[/color]

    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.
    [color=blue]
    > but i got the same problem[/color]

    BAD. Broken as designed.


    PointedEars

    Comment

    • Marcello Console

      #3
      Re: window.open location.href frame

      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.ph p?tema=$col_val ue\"
      target=\"corpo\ ">$col_valu e</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.selectedInde x
      || o.selectedIndex < 0)
      return false;
      var aut = o.options[o.selectedIndex].value;
      var f =
      (typeof encodeURICompon ent != "undefined"
      ? encodeURICompon ent
      : (typeof escape != "undefined"
      ? escape
      : dummy));
      parent.corpo.lo cation =
      'http://www.laltrarete. it/mipiace/corpo.php?autor e='
      + f(aut);
      return true;
      }
      </script>

      <form action="" onsubmit="selAu t(this)">
      seleziona gli articoli per autore:
      <select name="autore" >
      <?php
      $queryAutore=my sql_query("sele ct username
      from autori");
      while
      ($line=mysql_fe tch_row($queryA utore){
      foreach ($line as $autore) {
      print ("<option name=\"autore\"
      value=\"$autore \">$autore</option>"); }
      }
      ?>
      </select>
      <input type=submit value="selezion a" >
      </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).
      [color=blue]
      >also providing a server-side
      >alternative with the `action' attribute[/color]
      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!

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: window.open location.href frame

        Marcello Console wrote:
        [color=blue]
        > Thank you very much, Thomas.[/color]

        You are welcome.
        [color=blue]
        > It was a long and egsaustive help. Nevertheless, it seems it
        > still doesn't work.[/color]

        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.
        [color=blue]
        > At the moment my menu.php is
        >
        >
        >
        > <?php[/color]

        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.
        [color=blue]
        > [...]
        > <form action="" onsubmit="selAu t(this)">[/color]

        selAut(...), as it was rewritten by me, requires a reference to an
        HTMLSelectEleme nt 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*.
        [color=blue]
        > (upper case in the previous message was mine, just for emphasis).[/color]

        Better to use *bold*, /italic/ and/or _underlined_ instead. Good
        NetNews clients even format the text on display as described above.
        [color=blue][color=green]
        >> also providing a server-side alternative with the `action' attribute[/color]
        >
        > yes but how can i do that?[/color]

        <form action="alterna tive.php" ... onsubmit="retur n 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="alterna tive.php"
        ...
        onsubmit="selAu t(this); return false;"
        ...[color=blue]
        >[/color]

        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&na me2=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_global s=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]

        Comment

        • Marcello Console

          #5
          Re: window.open location.href frame

          As i don't see my reply, i post it again.
          Sorry if it is a deja-view for you.[color=blue]
          >Server-side script code is not useful for ...[/color]
          yes i know, but imput that rows in order to make more clear what i
          whanted to do.
          [color=blue]
          >selAut(...), as it was rewritten by me, requires a >reference to an[/color]
          HTMLSelectEleme nt 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?aut ore...... Isn't it
          strange?


          [color=blue][color=green]
          >>also providing a server-side alternative with the `action' >>[/color][/color]
          attribute[color=blue]
          > yes but how can i do that?[color=green]
          >> <form action="alterna tive.php" ... onsubmit="retur n >selAut(this) "[/color][/color]
          ...>

          I know i could put corpo.php?autor e=$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.
          [color=blue]
          > You should read more on JavaScript and DOM(s) before you >continue[/color]
          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!

          Comment

          Working...