By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,599 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,599 IT Pros & Developers. It's quick & easy.

is this a simple javascript syntax problem???

P: n/a
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="JavaScript1.2">
<!--
//Secify scroller contents
var line=new Array()
var totlines=<?php echo $msgctr; ?>
for (i=0;i<=totlines;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
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Owen Parker wrote:
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="JavaScript1.2">
<!--
//Secify scroller contents
var line=new Array()
var totlines=<?php echo $msgctr; ?>
for (i=0;i<=totlines;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

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
Jul 20 '05 #2

P: n/a
Fred Serry wrote:


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

echo "</script>\n";

should result in:

<script type=text/javascript>


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


And don't forget to declare the array as I did ;-)
Jul 20 '05 #3

P: n/a
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="JavaScript1.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="11px"
...
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!
Jul 20 '05 #4

P: n/a
Fred Serry wrote on 02 Dec 2003:

<snipped original post>

This...
echo "<script type=text/javascript>\n";
<snip>

....and this...
<script type=text/javascript>


<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.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.