Javascript program not being called

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

    #16
    Re: Javascript program not being called

    On Tue, 29 Jun 2004 15:59:13 +0100, John D wrote:
    [color=blue]
    > ..Boy, are we scratching our heads on this one![/color]

    Perhaps supplying an URL might be more
    productive, I did not see one anywhere
    in the thread.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology

    Comment

    • Richard Cornford

      #17
      Re: Javascript program not being called

      John D wrote:[color=blue][color=green]
      >> It is often said that the use of - eval - is never necessary anyway,
      >> but that one of the many good reasons for not using it is that it
      >> masks errors.[/color]
      >
      > So is what you are saying that when we test the script from a browser
      > the eval, even though there is a problem, still displays the feed.[/color]

      I have no idea what that sentence (question?) is intended to mean.
      [color=blue]
      > but when the script is called from another page the eval still fails
      > but nothing is returned[/color]

      The code you posted was going to error whatever you did with it. As you
      haven't provided any real details of the context in which you were
      attempting to use that script is it not possible to say whether that is
      the actual reason for its failure or whether something else stops it
      form working ahead of the inevitable syntax error.
      [color=blue]
      > Do you know a JavaScript way of retrieving QueryString related data?[/color]

      An all singing and dancing query string reading method might go:-

      /* This function call creates an interface to the name value pairs
      from the query string associated with the URL of the current page
      in the browsers. The interface is available as a global variable
      called - queryStrings - and has three methods:-

      queryStrings.ge tCountFor(name) ; - Returns the number of values found
      in the query string under the - name - provided as a parameter,
      or numeric zero if no elements exist under the name.

      queryStrings.ge tValueFor(name, index); - Returns the value found on
      the query string associated with the - name - provided as the
      first parameter. The second parameter is optional and represents
      an index into an array of the values found for the name. The
      index defaults to zero if no value is provided. If no value is
      found under the index, or no values exist under the name, then
      undefined is returned. Otherwise a string value is returned for
      each value provided on the query string associated with the
      name, or, if a name was found on the query string with no
      associated value this method returns boolean true;

      queryStrings.ge tNames(); - Returns a reference to an Array of all
      of the names found on the query string. Any modifications made
      to the array will persist and be present in the Array that will
      be returned by later calls, but will not alter the name value
      pairs returned by the other methods.

      */
      var queryStrings = (function(){
      var list = {};
      var keyList = [];
      var global = this;
      var unsc = (global.decodeU RIComponent)?'d ecodeURICompone nt':
      'unescape';
      var nameSafe = [' ',''];
      function addItem(name, value){
      nameSafe[1] = name;
      var sName = nameSafe.join(' ');
      if(list[sName]){
      list[sName][list[sName].length] = value;
      }else{
      list[sName] = [value];
      keyList[keyList.length] = name;
      }
      }
      if(typeof location != 'undefined'){
      var nvp,ofSet, temp = location.search ||location.href ||'';
      if((ofSet = temp.indexOf('? ')) > -1){
      temp = temp.split("#")[0];
      temp = temp.substring( (ofSet+1), temp.length);
      var workAr = temp.split('&') ;
      for(var c = workAr.length;c--;){
      nvp = workAr[c].split('=');
      if(nvp.length > 1){
      addItem(global[unsc](nvp[0]),global[unsc](nvp[1]));
      }else if(nvp.length == 1){
      addItem(global[unsc](nvp[0]), true);
      }
      }
      }
      }
      return ({
      getCountFor:fun ction(name){
      nameSafe[1] = name;
      var sName = nameSafe.join(' ');
      return ((list[sName] && list[sName].length)|0);
      },
      getValueFor:fun ction(name, index){
      nameSafe[1] = name;
      var sName = nameSafe.join(' ');
      if(list[sName]){
      return list[sName][(index|0)];
      } //else return undefined (by default)
      },
      getNames:functi on(){
      return keyList;
      }
      });
      })();

      - but a much simpler and more direct implementation should be possible
      an any real context. But for that you (I) have to know what is
      known/guaranteed about the nature of the query strings in use.
      [color=blue]
      > Any help appreciated.
      >
      > John
      >
      > P.S. the fellow I am asking this for says "heh, hands up I
      > copied it from the site of a so called JavaScript expert!!!"[/color]

      If you see - eval - used in javascript source code *always* initially
      suspect that its author is non-expert until proven otherwise (the same
      goes for - navigator.userA gent -), and it is unlikely that it will be
      proven otherwise.

      Richard.


      Comment

      • James Moe

        #18
        Re: Javascript program not being called

        John D wrote:[color=blue]
        > I have a web page that attempts to call a piece of Javascript, which
        > attempts to transform an xml file and an xslt file into Html.
        >
        > The call is here (A) :
        >
        > <script language = "JavaScript " src = "customfeed.htm l?Ga_Id=36475"
        > type="text/javascript"></script>
        >[/color]
        "customfeed.htm l?Ga_Id=36475" is not javascript. You must use a <a
        href="customfee d.html?Ga_Id=36 475"> to get the script to run.
        If you have Mozilla, use "Tools->Web Development->Javascript Console"
        to see what errors are being generated. Mozilla also offers a javascript
        debugger.

        --
        jmm dash list at sohnen-moe dot com
        (Remove .TRSPAMTR for email)

        Comment

        • John D

          #19
          Re: Javascript program not being called - eval from hell

          Thank you all for your help with this; we have removed the evil eval, and it
          is working as expected!!


          Comment

          Working...