is this a simple javascript syntax problem???

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

    is this a simple javascript syntax problem???

    Hi all

    I am not a java programmer but i can hack at it a bit. I am trying to
    allow a user to define the text in a simple javascript text scroller.
    The data is stored as multiple records in a MYSQL table. I read these
    using PHP and the result is an array if you will of each of the
    'lines' or records that the user wants displayed in the scroller.

    $msgctr is an integer that is the total number of records passed by
    PHP
    $msgline is the array of each record

    Here is the code snip...

    <script language="JavaS cript1.2">
    <!--
    //Secify scroller contents
    var line=new Array()
    var totlines=<?php echo $msgctr; ?>
    for (i=0;i<=totline s;i++){
    line[i]=<?php echo $msgline; ?>
    }

    //line[1]=" these are what used to be used to load the scroller"
    //line[2]=" line 2 ... "
    //line[3]=" line 3 ..."
    ..
    ..
    ..

    I hate to admit it but i feel that this is simply a syntax error but I
    cant find anything wrong and i cant seem to get any error message feed
    back from the browser when it tries to load...

    Am I way off track here or do I have a smack to the forehead in my
    near future...

    many thanx in advance for any advice you may have that will help me
    move on from this 5 minute job i have spent an hour on :)

    l8r
    owen
  • Fred Serry

    #2
    Re: is this a simple javascript syntax problem???

    Owen Parker wrote:[color=blue]
    > Hi all
    >
    > I am not a java programmer but i can hack at it a bit. I am trying to
    > allow a user to define the text in a simple javascript text scroller.
    > The data is stored as multiple records in a MYSQL table. I read these
    > using PHP and the result is an array if you will of each of the
    > 'lines' or records that the user wants displayed in the scroller.
    >
    > $msgctr is an integer that is the total number of records passed by
    > PHP
    > $msgline is the array of each record
    >
    > Here is the code snip...
    >
    > <script language="JavaS cript1.2">
    > <!--
    > //Secify scroller contents
    > var line=new Array()
    > var totlines=<?php echo $msgctr; ?>
    > for (i=0;i<=totline s;i++){
    > line[i]=<?php echo $msgline; ?>
    > }
    >
    > //line[1]=" these are what used to be used to load the scroller"
    > //line[2]=" line 2 ... "
    > //line[3]=" line 3 ..."
    > .
    > .
    > .
    >
    > I hate to admit it but i feel that this is simply a syntax error but I
    > cant find anything wrong and i cant seem to get any error message feed
    > back from the browser when it tries to load...
    >
    > Am I way off track here or do I have a smack to the forehead in my
    > near future...
    >
    > many thanx in advance for any advice you may have that will help me
    > move on from this 5 minute job i have spent an hour on :)
    >
    > l8r
    > owen[/color]


    Hi,

    If your objective is to construct a javascript array from the php array you
    are confusing the two:


    <?php
    echo "<script type=text/javascript>\n";
    $cnt=0;
    foreach ($msgline as $value) {
    echo "line[$cnt]=\"$value\";\n" ;
    $cnt++;
    }

    echo "</script>\n";
    ?>

    should result in:

    <script type=text/javascript>
    line[0]=" line 1...";
    line[1]=" line 2...";
    line[2]=" line 3...";
    </script>

    Fred


    Comment

    • Fred Serry

      #3
      Re: is this a simple javascript syntax problem???

      Fred Serry wrote:[color=blue]
      >
      >
      > <?php
      > echo "<script type=text/javascript>\n";[/color]

      echo "var line = new Array();";
      [color=blue]
      > $cnt=0;
      > foreach ($msgline as $value) {
      > echo "line[$cnt]=\"$value\";\n" ;
      > $cnt++;
      > }
      >
      > echo "</script>\n";[color=green]
      >>[/color]
      >
      > should result in:
      >
      > <script type=text/javascript>[/color]

      var line = new Array();
      [color=blue]
      > line[0]=" line 1...";
      > line[1]=" line 2...";
      > line[2]=" line 3...";
      > </script>
      >[/color]

      And don't forget to declare the array as I did ;-)


      Comment

      • owen parker

        #4
        Re: is this a simple javascript syntax problem???

        hi Fred and thanx for the reply. I like your suggestion and thot it was
        the answer. however, i cannot get it to produce the line[] vars. Here
        is the setup boiled down. im pretty sure this is one of those bonehead
        mistakes on my part.

        the php file is simple a collection of 'routines' that are included at
        the head of each page. the routines are all java scripts (4 in total of
        which the scroller is one) I stuck a section in the <head> to open up
        the MYSQL and load $msgline with the array of data. I threw in a quick
        print section to test that $msgline was loaded properly and sure enough
        it printed out the 13 test records.

        In the <body> i have the following:

        ...
        <div id="topscroller ">
        <script language="JavaS cript1.2">
        <!--
        //Secify scroller contents
        var line=new Array()
        <?php
        $cnt=0;
        foreach ($msgline as $value) {
        echo "line[$cnt]=\"$value\";\n" ;
        $cnt++;
        }
        ?>

        //Specify font size for scoller
        var ts_fontsize="11 px"
        ...


        I dont have the script designation or the new array in the php snip as
        per you example becasue I think you may have been thinking of something
        a tad different but i tried it there as well and no difference just to
        make sure.

        This is so simple 'looking' that I cannot see the problem. Can you (or
        anyone else that sees this). I am certain I have used php to pop in
        variables in java before but the array is the bump in the road, but it
        should work shouldnt it?

        many thanx in advance for any help or pointers to help...

        l8r
        owen

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Michael Winter

          #5
          Re: is this a simple javascript syntax problem???

          Fred Serry wrote on 02 Dec 2003:

          <snipped original post>

          This...
          [color=blue]
          > echo "<script type=text/javascript>\n";[/color]

          <snip>

          ....and this...
          [color=blue]
          > <script type=text/javascript>[/color]

          <snip>

          ....are grossly in error. Attribute values *must* be quoted if they
          contain characters that are not alphanumeric, hyphens, periods,
          underscores or colons. That is why the specification recommends that
          *all* attribute values are to be quoted, even when the quotes are not
          needed. It prevents mishaps like that.

          Mike

          --
          Michael Winter
          M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)

          Comment

          Working...