473,666 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>
Nov 22 '05 #1
6 2194
Ian Davies wrote:

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
<snip>
function Fill_Sub()
{

<?PHP
This is in the wrong spot...
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;
}
This is where the "<?php" should be...
$Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
StatusID = 1 ORDER BY SubjectDesc ASC";
$Result = mysql_query($Qu ery, $conn );


<snip>

--
Justin Koivisto, ZCE - ju****@koivi.co m
http://koivi.com
Nov 22 '05 #2
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" <ju****@koivi.c om> wrote in message
news:uP******** ************@on voy.com...
Ian Davies wrote:

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

<snip>
function Fill_Sub()
{

<?PHP


This is in the wrong spot...
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;
}


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


<snip>

--
Justin Koivisto, ZCE - ju****@koivi.co m
http://koivi.com

Nov 22 '05 #3
Ian Davies wrote:
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


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 - ju****@koivi.co m
http://koivi.com
Nov 23 '05 #4
Ian Davies wrote:
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
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.

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
Asking PHP questions in a JavaScript group? Thinking JavaScript is
Java? ;-)

<?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">
The language attribute is deprecated, type is required:

<script type="text/javascript">


function BodyLoad()
{

var select = document.FormNa me.MainCategory ;

select.options[0] = new Option("Choose One");
select.options[0].value = 0;
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.


<?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 ) {
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.


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


A select element with no options is invalid HTML.

[...]
--
Rob
Nov 23 '05 #5
RobG wrote:
When posting code, post what is received at the client (use view
source). The PHP side should be discussed in a PHP forum.
It was - 4 of them.
Asking PHP questions in a JavaScript group? Thinking JavaScript is
Java? ;-)


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 - ju****@koivi.co m
http://koivi.com
Nov 23 '05 #6
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
http://www.iddsoftware.co.uk/Questio...ionsBrowse.php

Ian
"Justin Koivisto" <ju****@koivi.c om> wrote in message
news:Xe******** *************** *******@onvoy.c om...
Ian Davies wrote:
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
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 - ju****@koivi.co m
http://koivi.com

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4076
by: Ian Davies | last post by:
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\iddsoftware.co.uk\user\htdocs\QuestionDB\Questions.php on line 42
14
2630
by: dbldeegd | last post by:
My Java Script executes fine on an test HTML page, but on the required page which is php results in an error. the page The script drops in message box when the page is loaded since the script works the problemshould lie elsewhere.. line 451 <div id="dropin" style="LEFT: 200px; VISIBILITY: hidden; WIDTH: 500px; POSITION: absolute; TOP: 100px; HEIGHT: 100px; BACKGROUND-COLOR: #ccccff"> more...html code.....
12
2951
by: Inny | last post by:
Im trying to rewrite a link with a href function. I need to parse a query string within it ('+tid') But all attempts Have falied. The current onclick/ link function <a href="java script:who_posted();">Who Posted?</a> is attached to my forums 'replys' number colum in forum veiw' {i have no direct access} it appears in the staus bar on hover as
13
1850
by: Gilles Ganault | last post by:
Hello Is there a tool on Linux/FreeBSD that can parse a PHP script to make sure there's no compile-time issues? I just noticed that I copy/pasted some code that had lines longer that can fit in the SSH terminal window, and that caused a run-time error as reported in the /var/log/httpd-error.log but not in the browser: PHP Notice: Undefined index: etablissemen\nt in
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.