You are here: Re: Parse error with php/java script « All PHP « IT news, forums, messages
Re: Parse error with php/java script

Posted by RobG on 11/23/05 02:06

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\iddsoftware.co.uk\user\htdocs\QuestionDB\Questions.php on line
> 42
>
> line 42 being
> var mainselect = document.FormName.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">Logout</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="JavaScript">

The language attribute is deprecated, type is required:

<script type="text/javascript">


>
> function BodyLoad()
> {
>
> var select = document.FormName.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_array($Result) ) {
> echo "select.options[".$ctr."] = new
> Option(\"".$Row['SubjectNo']."\");\n";
> echo "select.options[".$ctr."].value = \"".$Row['SubjectNo']."\";\n";
> $ctr++;
> }
> ?>
> }
>
> function Fill_Sub()
> {
>
> <?PHP
> var mainselect = document.FormName.MainCategory;
> var subselect = document.FormName.SubCategory;
>
> if( mainselect.options[mainselect.selectedIndex].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.length = 0;
> }
[...]
> <TD>
> <SELECT name="SubCategory" size="4">
> </SELECT>
> </TD>

A select element with no options is invalid HTML.

[...]


--
Rob

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация