473,657 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 20 '05 #1
4 2231
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="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

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

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

Similar topics

1
6010
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that required fields in a form have values. I'm writing the values to the client using document.write only so that I can confirm that the values are there to be played with - this is not the final result so please (unless it's leading to the script failure)...
6
2529
by: Andy Fish | last post by:
Hi, I want to use an anchor tag to invoke some javascript and I've read that it's bad form to use <a href="javascript:foo()"> I've read endless usenet posts and hint sites on the net, they all suggest different things and I can't get any kind of consistency, and I can't find any solution that works properly for IE, opera and mozilla. many of the recommended solutions go something like this:
6
2004
by: Alex Fitzpatrick | last post by:
Just by way of introduction, I'm currently the principal developer and maintainer of the a JavaScript editor plug-in for Eclipse. https://sourceforge.net/projects/jseditor/ The plug-in as it stands supports syntax highlighting and outlining of functions, classes and their methods.] When I took over the project in June it was for the purpose of adding outlining facilities for JavaScript written in an OO style with classes and so on. I...
5
4675
by: Mark 123 | last post by:
Hi I have a form with the input fields: ProductName Quantity and output fields: ProductPrice
1
2547
by: David | last post by:
Safari under Mac OSX accepts a "Execute Javascript" apple event. Thus, you can send an event to if from another application (or from the Scripts menu). I would like an event that does the equivalent of "set selection", so I can fill in some text in a text entry box. In particular, I have a visa card number stored in the Keychain database. I retrieve it with an Applescript, then would like to execute the equivalent of "do javascript...
3
1639
by: Marc Llenas | last post by:
Hi there, I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas? The function being called is: <script language="JavaScript" type="text/javascript"> function checkform ( form ) {
20
2550
by: Larry Woods | last post by:
I'm drawing a blank... What is the regular expression for search a string for NO occurances of a substring? Example: I want to find all lines that do NOT have the substing "image" in them. TIA, Larry Woods
27
4607
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res = $doc->loadHTMLFile("./aBasicSearchResult.html"); if ( $res == true ) { $zip = $doc->getElementById('zipRaw_id')->value; if ( 0 != $zip ) {
13
2033
by: aum | last post by:
Hi, I'm a Python programmer, just starting to get into javascript. On reading some of the js guides, and not liking any of the OO usage patterns I saw, I've cooked up something which python folks might find to taste. Here's the code - first the 'engine', then some code demonstrating the usage patterns. For me (and maybe for some of you), it promotes readability and some
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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
8730
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
6163
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
5632
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
4151
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...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
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.