Parse error with php/java script

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

    Parse error with php/java script

    Hello
    I have found the following script php/java for dynamic menu lists. Where a
    selection from the first updates (filters items in) the other. I have
    modified it for my tables.
    However I am getting an error

    Parse error: parse error, unexpected T_VAR in
    e:\domains\i\id dsoftware.co.uk \user\htdocs\Qu estionDB\Questi ons.php on line
    42

    line 42 being
    var mainselect = document.FormNa me.MainCategory ;

    Im fairly new to php and dont use Java upto now. Can anyone see where I ve
    gone wrong

    <?php
    session_start() ;
    include("../include/connection.php" );
    include("../Secure/login.php");
    $Heading= 'QUESTION SELECTOR';
    $Menu='<a href="../Secure/logout.php">Log out</a><br>';
    include 'HeadQuest.php' ;


    $Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
    StatusID = 1 ORDER BY SubjectDesc ASC";
    $Result = mysql_query( $Query, $conn );

    ?>

    <HTML>
    <HEAD>
    <SCRIPT language="JavaS cript">

    function BodyLoad()
    {

    var select = document.FormNa me.MainCategory ;

    select.options[0] = new Option("Choose One");
    select.options[0].value = 0;

    <?PHP

    $ctr = 1;
    While( $Row = mysql_fetch_arr ay($Result) ) {
    echo "select.opt ions[".$ctr."] = new
    Option(\"".$Row['SubjectNo']."\");\n";
    echo "select.opt ions[".$ctr."].value = \"".$Row['SubjectNo']."\";\n";
    $ctr++;
    }
    ?>
    }

    function Fill_Sub()
    {

    <?PHP
    var mainselect = document.FormNa me.MainCategory ;
    var subselect = document.FormNa me.SubCategory;

    if( mainselect.opti ons[mainselect.sele ctedIndex].value != 0 ) {

    subselect.lengt h = 0;
    }

    $Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
    StatusID = 1 ORDER BY SubjectDesc ASC";
    $Result = mysql_query($Qu ery, $conn );

    while( $Row = mysql_fetch_arr ay($Result) ) {
    ?>


    if( mainselect.opti ons[mainselect.sele ctedIndex].text == "<?PHP echo
    $Row['SubjectNo']; ?>" ) {
    <?PHP

    $Query2 = "SELECT TopicID, TopicDesc, KS, SubjectNo FROM ttopic WHERE
    StatusID = 1 AND SubjectNo = ".$row['SubjectNo']." ORDER BY TopicDesc ASC";


    $Result2 = mysql_query($Qu ery2, $conn );

    $ctr = 0;

    While( $Row2 = mysql_fetch_arr ay($Result2) ) {
    echo "subselect.opti ons[".$ctr."] = new
    Option(\"".$Row 2['TopicID']."\");\n";
    echo "subselect.opti ons[".$ctr."].value =
    \"".$Row2['TopicID']."\";\n";
    $ctr++;
    }
    ?>
    }
    }

    <?PHP
    }

    mysql_close($co nn);
    ?>
    }

    </SCRIPT>
    </HEAD>

    <BODY onload="BodyLoa d();">
    <FORM name="FormName" method="POST" action="">
    <TABLE border="1">
    <TR>
    <TD>Main Category</TD>
    <TD>Sub Category</TD>
    </TR>
    <TR>
    <TD>
    <SELECT name="MainCateg ory" onchange="Fill_ Sub();">
    </SELECT>
    </TD>

    <TD>
    <SELECT name="SubCatego ry" size="4">
    </SELECT>
    </TD>
    </TR>
    </TABLE>
    </FORM>
    </BODY>
    </HTML>


  • Justin Koivisto

    #2
    Re: Parse error with php/java script

    Ian Davies wrote:[color=blue]
    >
    > Parse error: parse error, unexpected T_VAR in
    > e:\domains\i\id dsoftware.co.uk \user\htdocs\Qu estionDB\Questi ons.php on line
    > 42
    >[/color]
    <snip>
    [color=blue]
    > function Fill_Sub()
    > {
    >
    > <?PHP[/color]

    This is in the wrong spot...
    [color=blue]
    > var mainselect = document.FormNa me.MainCategory ;
    > var subselect = document.FormNa me.SubCategory;
    >
    > if( mainselect.opti ons[mainselect.sele ctedIndex].value != 0 ) {
    >
    > subselect.lengt h = 0;
    > }[/color]

    This is where the "<?php" should be...
    [color=blue]
    > $Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
    > StatusID = 1 ORDER BY SubjectDesc ASC";
    > $Result = mysql_query($Qu ery, $conn );[/color]

    <snip>

    --
    Justin Koivisto, ZCE - justin@koivi.co m

    Comment

    • Ian Davies

      #3
      Re: Parse error with php/java script

      Thanks
      That helped
      But now get a syntax error on line 69
      which is

      echo "subselect.opti ons[".$ctr."].value =
      \"".$Row2['TopicID']."\";\n";

      my debugger is saying

      if( mainselect.opti ons[mainselect.sele ctedIndex].value == "12" ) {
      Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result
      resource in e:\domains\i\my site\user\htdoc s\myfolder\Ques tions.php on line
      67
      } }

      It would seem that there is a problem with

      mainselect.opti ons[mainselect.sele ctedIndex].value

      Ian



      "Justin Koivisto" <justin@koivi.c om> wrote in message
      news:uPidnaxdQ-f-Ch7eRVn-ow@onvoy.com...[color=blue]
      > Ian Davies wrote:[color=green]
      > >
      > > Parse error: parse error, unexpected T_VAR in
      > > e:\domains\i\id dsoftware.co.uk \user\htdocs\Qu estionDB\Questi ons.php on[/color][/color]
      line[color=blue][color=green]
      > > 42
      > >[/color]
      > <snip>
      >[color=green]
      > > function Fill_Sub()
      > > {
      > >
      > > <?PHP[/color]
      >
      > This is in the wrong spot...
      >[color=green]
      > > var mainselect = document.FormNa me.MainCategory ;
      > > var subselect = document.FormNa me.SubCategory;
      > >
      > > if( mainselect.opti ons[mainselect.sele ctedIndex].value != 0 ) {
      > >
      > > subselect.lengt h = 0;
      > > }[/color]
      >
      > This is where the "<?php" should be...
      >[color=green]
      > > $Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects[/color][/color]
      WHERE[color=blue][color=green]
      > > StatusID = 1 ORDER BY SubjectDesc ASC";
      > > $Result = mysql_query($Qu ery, $conn );[/color]
      >
      > <snip>
      >
      > --
      > Justin Koivisto, ZCE - justin@koivi.co m
      > http://koivi.com[/color]


      Comment

      • Justin Koivisto

        #4
        Re: Parse error with php/java script

        Ian Davies wrote:[color=blue]
        > Thanks
        > That helped
        > But now get a syntax error on line 69
        > which is
        >
        > echo "subselect.opti ons[".$ctr."].value =
        > \"".$Row2['TopicID']."\";\n";
        >
        > my debugger is saying
        >
        > if( mainselect.opti ons[mainselect.sele ctedIndex].value == "12" ) {
        > Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result
        > resource in e:\domains\i\my site\user\htdoc s\myfolder\Ques tions.php on line
        > 67
        > } }
        >
        > It would seem that there is a problem with
        >
        > mainselect.opti ons[mainselect.sele ctedIndex].value[/color]

        Or there's something wrong with the query. You blindly start a while
        loop without first checking to see if the query has succeeded. In this
        case, if $Result isn't a valid result resource, the query failed for
        some reason... to help debug, use mysql_error() to see what the problem is.

        --
        Justin Koivisto, ZCE - justin@koivi.co m

        Comment

        • RobG

          #5
          Re: Parse error with php/java script

          Ian Davies wrote:[color=blue]
          > Hello
          > I have found the following script php/java for dynamic menu lists. Where a
          > selection from the first updates (filters items in) the other. I have
          > modified it for my tables.
          > However I am getting an error[/color]

          When posting code, post what is received at the client (use view
          source). The PHP side should be discussed in a PHP forum.

          Once you have sorted out what the client should get, then you can work
          out how to generate it.

          [color=blue]
          > Parse error: parse error, unexpected T_VAR in
          > e:\domains\i\id dsoftware.co.uk \user\htdocs\Qu estionDB\Questi ons.php on line
          > 42
          >
          > line 42 being
          > var mainselect = document.FormNa me.MainCategory ;
          >
          > Im fairly new to php and dont use Java upto now. Can anyone see where I ve
          > gone wrong[/color]

          Asking PHP questions in a JavaScript group? Thinking JavaScript is
          Java? ;-)

          [color=blue]
          > <?php
          > session_start() ;
          > include("../include/connection.php" );
          > include("../Secure/login.php");
          > $Heading= 'QUESTION SELECTOR';
          > $Menu='<a href="../Secure/logout.php">Log out</a><br>';
          > include 'HeadQuest.php' ;
          >
          >
          > $Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
          > StatusID = 1 ORDER BY SubjectDesc ASC";
          > $Result = mysql_query( $Query, $conn );
          >
          > ?>
          >
          > <HTML>
          > <HEAD>
          > <SCRIPT language="JavaS cript">[/color]

          The language attribute is deprecated, type is required:

          <script type="text/javascript">

          [color=blue]
          >
          > function BodyLoad()
          > {
          >
          > var select = document.FormNa me.MainCategory ;
          >
          > select.options[0] = new Option("Choose One");
          > select.options[0].value = 0;[/color]

          IE has issues with setting option attributes this way. Set all the
          values in one go (hey, saves a line of code too):

          select.options[0] = new Option("Choose One", "0", true, true);


          sets the first option to have text 'Choose One', value as '0', default
          selected as true and currently selected as true.

          [color=blue]
          >
          > <?PHP
          >
          > $ctr = 1;
          > While( $Row = mysql_fetch_arr ay($Result) ) {
          > echo "select.opt ions[".$ctr."] = new
          > Option(\"".$Row['SubjectNo']."\");\n";
          > echo "select.opt ions[".$ctr."].value = \"".$Row['SubjectNo']."\";\n";
          > $ctr++;
          > }
          > ?>
          > }
          >
          > function Fill_Sub()
          > {
          >
          > <?PHP
          > var mainselect = document.FormNa me.MainCategory ;
          > var subselect = document.FormNa me.SubCategory;
          >
          > if( mainselect.opti ons[mainselect.sele ctedIndex].value != 0 ) {[/color]

          The value of a form control is always returned as a string, so be
          careful when evaluating it. In this case it is OK because the string
          '0' and number 0 will be evaluated as you expect, but sometimes it will
          trip you up.

          [color=blue]
          >
          > subselect.lengt h = 0;
          > }[/color]
          [...][color=blue]
          > <TD>
          > <SELECT name="SubCatego ry" size="4">
          > </SELECT>
          > </TD>[/color]

          A select element with no options is invalid HTML.

          [...]


          --
          Rob

          Comment

          • Justin Koivisto

            #6
            Re: Parse error with php/java script

            RobG wrote:[color=blue]
            > When posting code, post what is received at the client (use view
            > source). The PHP side should be discussed in a PHP forum.[/color]

            It was - 4 of them.
            [color=blue]
            > Asking PHP questions in a JavaScript group? Thinking JavaScript is
            > Java? ;-)[/color]

            More like someone not sure if it was a php or js thing. The post went to
            4 php groups, and one js group...

            --
            Justin Koivisto, ZCE - justin@koivi.co m

            Comment

            • Ian Davies

              #7
              Re: Parse error with php/java script

              Hello

              The script here is modified from a previous script where I have not
              atempted to use java to update a second dropdownmenu/listbox (havent decided
              which to use yet) from the item selected in the first. In the previous
              script I use the exact same sqls which work fine.
              Go here to see these SQLs working in the dropdown lists


              Ian


              "Justin Koivisto" <justin@koivi.c om> wrote in message
              news:XeidnVQDys 8rNh7enZ2dnUVZ_ tGdnZ2d@onvoy.c om...[color=blue]
              > Ian Davies wrote:[color=green]
              > > Thanks
              > > That helped
              > > But now get a syntax error on line 69
              > > which is
              > >
              > > echo "subselect.opti ons[".$ctr."].value =
              > > \"".$Row2['TopicID']."\";\n";
              > >
              > > my debugger is saying
              > >
              > > if( mainselect.opti ons[mainselect.sele ctedIndex].value == "12" ) {
              > > Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL[/color][/color]
              result[color=blue][color=green]
              > > resource in e:\domains\i\my site\user\htdoc s\myfolder\Ques tions.php on[/color][/color]
              line[color=blue][color=green]
              > > 67
              > > } }
              > >
              > > It would seem that there is a problem with
              > >
              > > mainselect.opti ons[mainselect.sele ctedIndex].value[/color]
              >
              > Or there's something wrong with the query. You blindly start a while
              > loop without first checking to see if the query has succeeded. In this
              > case, if $Result isn't a valid result resource, the query failed for
              > some reason... to help debug, use mysql_error() to see what the problem[/color]
              is.[color=blue]
              >
              > --
              > Justin Koivisto, ZCE - justin@koivi.co m
              > http://koivi.com[/color]


              Comment

              Working...