Re: nesting JS in echo's



703designs wrote:
On Nov 8, 7:21 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
Seni Seven wrote:
Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote in comp.lang.php:
Request-1 wrote:
"Jerry Stuckle" <jstuck...@xxxxxxxxxxxxx> wrote in message
news:gf2t4m$inr$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Request-1 wrote:
hi folks,
html coder here, new and terrified * of php!!
aaaaaa!
i'm trying to bury a JS script to rotate a photo, in a page i
converted from html to php.
the conversion went well, it was to use a php session cookie to
stop the repeating of an embedded video file on a per session
basis; i amended the php code to display a still pic if the session
cookie value was nil.
worked fine.
thought I'd try integrating a tested and true JS image random
rotator script into the echo command, but the problem was the
syntax of the single quotes and double quotes needed in the
doc.write and variable sequences in the JS.
i tried escaping the double quotes (my echo used double quotes),
but to no avail.
here's the JS CODE i use in the tail end of my PHP. "picnumber" is
the variable holding the randomly assigned number that chooses the
picture.
any help much appreciated..
++++++++++++++++
{ echo "
<script language='JavaScript1.2'>
<!-- begin
document.write(\"'<img src='images/swap/'+ picnumber +
'.jpg'>\");
// end -->
</script>
"; }
++++++++++++++++++++++++++
thanks
You have an extra single quote before <img ...
Hi Jerry,
the single quote is actually necessary in JS when you're using
document.write to add strings in series (is it called "concatenating"
or something?). so the <img src...> statement was broken down into 3
seperate stings to be re-joined - all within the double-quote nested
doc.write stmt. my mistake was to leave the image path in single
quotes; instead I tried "escaped double quotes" to complete the image
path, like so,
{ echo "<script language='JavaScript1.2'>\n";
echo "<!-- begin \n";
echo "document.write('<img src=\"images/swap/' + picnumber
+'.jpg\"
width=\"320\" height=\"240\" border=\"0\" alt=\"Fitness Training
Image\">');\n";
echo "// end -->\n";
echo "</script>"; }
but no avail. still no pic shows up.
anyway. i get really confused with all the nested stuff and
single-double quotes. i may try that "heredoc" thing that Thomas
suggested. I'll need a couple of beers first. Friday night on
Javascript? Bad!
BTW - you don't need quotes around numeric values like your width,
height and border. Only non-numeric data.
Are you talking about generating strict (X)HTML? Quotes must be on all
element attributes in that case, regardless of attribute value type.
1. There is no indication this is XHTML.
2. You shouldn't use XHTML for web pages - it's not well supported by
some browser, not the least being IE 6 and 7.

HTML does NOT require quotes on numeric attributes.


Haha, where did you get that from? I've been building sites for ages
now with the XHTML doctype (transitional or strict, validates) and
never had any problems. I don't think I've ever had the desire or a
reason to use single quotes in HTML...

Thomas

Try google. It's well documented.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: nesting JS in echos
    ... converted from html to php. ... syntax of the single quotes and double quotes needed in the ... There is no indication this is XHTML. ...
    (comp.lang.php)
  • Re: nesting JS in echos
    ... converted from html to php. ... syntax of the single quotes and double quotes needed in the ... There is no indication this is XHTML. ...
    (comp.lang.php)
  • Re: nesting JS in echos
    ... converted from html to php. ... syntax of the single quotes and double quotes needed in the ... You shouldn't use XHTML for web pages - it's not well supported by some browser, not the least being IE 6 and 7. ...
    (comp.lang.php)
  • Re: [PHP] Tidy HTML source?
    ... Your innovation is helpful here, as you're nearly making HTML tags into PHP key words, eliminating some of the literal quoting that makes PHP+HTML so tiresome. ... The value of the attribute is any valid PHP expression and if they are literal strings there will be quotes, but then, you can also use heredoc if, for example, you are putting some JavaScript code into an event. ... I use heredoc extensively for both HTML markup and SQL queries, both when they appear in my PHP scripts and when they imported from separate files. ...
    (php.general)
  • Re: nesting JS in echos
    ... converted from html to php. ... syntax of the single quotes and double quotes needed in the ... There is no indication this is XHTML. ...
    (comp.lang.php)