php-general Digest 31 Jul 2006 05:31:58 -0000 Issue 4266
Topics (messages 239883 through 239889):
call a javascript within php
239883 by: Jochen Kaechelin
239884 by: Jay Blanchard
239885 by: Paul Novitski
Re: Saving a dynamic file
239886 by: Brady Mitchell
Re: PAYPAL TRANSACTION.
239887 by: Chris
Re: mb_substr()
239888 by: Chris
sorting in array
239889 by: weetat
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
How can I call a JavaScript inside php?
Thängs
--- End Message ---
--- Begin Message ---
[snip]
How can I call a JavaScript inside php?
[/snip]
Echo it out.
--- End Message ---
--- Begin Message ---
At 09:59 AM 7/30/2006, Jochen Kaechelin wrote:
How can I call a JavaScript inside php?
You can't literally call client-side JavaScript from server-side PHP
because they're executing at different times and in different
computers. PHP executes on the server then downloads the page to the
browser, then JavaScript executes in the browser.
What you can do is to write your PHP script so that it generates your
JavaScript code as part of the page download, set to execute
automatically when the page downloads. The JavaScript can either be
inline in the HTML page itself or linked to the HTML page with a
script tag and a SRC attribute that produces the desired JavaScript
on the fly, e.g.:
echo <<< hdJS
<script src="myJavaScriptGenerator.php?param=value"
type="text/javascript"></script>
hdJS;
If your JavaScript is static -- already written, not needing
modification -- you can simply link it to your PHP-generated HTML
page as usual:
echo <<< hdJS
<script src="myJavaScript.js" type="text/javascript"></script>
hdJS;
Another variation involves a static JS script that's fed
dynamically-generated variables by PHP. This isn't a shared variable
space between the two languages but more like a communication channel
between them:
$frog = 'Hello';
$dog = 'world';
echo <<< hdJS
<script type="text/javascript">
var frog = "$frog";
var dog = "$dog";
</script>
<script src="myJavaScript.js" type="text/javascript"></script>
hdJS;
Of course you can generate entire blocks of JavaScript logic with PHP
if need be, but I would suspect that in most cases you'd be better
off feeding a few key variables to a static JS script.
_________________________________________
Most of the time you'll want your JS script to execute after the HTML
finishes downloading, so that JavaScript will be able to find all the
page elements in the DOM. Three ways of doing this are:
1) Use the window.onload method in a linked JavaScript script:
window.onload = jsFunctionName;
function jsFunctionName()
{
...
}
Notice the lack of parentheses in the onload statement. This is
because you want to set window.onload equal to the content of the
function, not execute the function as would occur if you wrote
"window.onload = jsFunctionName();".
The window.onload statement wipes out any pre-existing onload
function. Multiple linked scripts can use this method cooperatively this way:
// save any pre-existing onload function
var uniqueVariableName = window.onload;
// do the following when the page finishes downloading:
window.onload = function()
{
// if there was a pre-existing onload
function, run it now
if (uniqueVariableName) uniqueVariableName();
// run the function
jsFunctionName();
}
// here's the function you want to execute when the page has loaded
function jsFunctionName()
{
...
}
In this example, "uniqueVariableName" is different for each script
that uses it. I usually use the name of the JavaScript file as part
of this variable name to ensure uniqueness.
Multiple onloads can also be implemented using the addEventListener method:
http://developer.mozilla.org/en/docs/DOM:element.addEventListener
2) Use the onLoad attribute in the body tag:
<body onLoad="jsFunctionName();">
...where jsFunctionName() is a function in a linked or inline script.
I don't recommend this method because it mixes HTML with scripting
more than is necessary. The more separate you keep them, the easier
both will be to maintain.
3) Insert the function call in a script statement at the bottom of
the HTML markup:
...
<script type="text/javascript">
jsFunctionName();
</script>
</body>
</html>
Same argument against mixing HTML with scripting, although one could
argue that this constitutes the same degree of mixing that occurs
with the <script src= tag.
Regards,
Paul
--- End Message ---
--- Begin Message ---
Depends on what you are planning to do with the file. Saving it to PDF is also
possible, take a look at http://fpdf.org and http://htmldoc.org/.
Brady
-----Original Message-----
Hi!!
I'm in the need of saving to a file a dynamic page that I generated from a PHP
script, taking data from a table!!
So far I have figured out two options:
1) Save the page as a XML document so it can be editable in a word processor
later. Do I have to write line by line until I'm done with the document?
2) Use a class to convert & save the dynamic page into a Word document.
Is there any other options available??
Regards
------------------------------------------------
MIGUEL GUIRAO AGUILERA
Logistica R8 - Telcel
Tel: (999) 960.7994
Este mensaje es exclusivamente para el uso de la persona o entidad a quien esta
dirigido; contiene informacion estrictamente confidencial y legalmente
protegida, cuya divulgacion es sancionada por la ley. Si el lector de este
mensaje no es a quien esta dirigido, ni se trata del empleado o agente
responsable de esta informacion, se le notifica por medio del presente, que su
reproduccion y distribucion, esta estrictamente prohibida. Si Usted recibio
este comunicado por error, favor de notificarlo inmediatamente al remitente y
destruir el mensaje. Todas las opiniones contenidas en este mail son propias
del autor del mensaje y no necesariamente coinciden con las de Radiomovil
Dipsa, S.A. de C.V. o alguna de sus empresas controladas, controladoras,
afiliadas y subsidiarias. Este mensaje intencionalmente no contiene acentos.
This message is for the sole use of the person or entity to whom it is being
sent. Therefore, it contains strictly confidential and legally protected
material whose disclosure is subject to penalty by law. If the person reading
this message is not the one to whom it is being sent and/or is not an employee
or the responsible agent for this information, this person is herein notified
that any unauthorized dissemination, distribution or copying of the materials
included in this facsimile is strictly prohibited. If you received this
document by mistake please notify immediately to the subscriber and destroy
the message. Any opinions contained in this e-mail are those of the author of
the message and do not necessarily coincide with those of Radiomovil Dipsa,
S.A. de C.V. or any of its control, controlled, affiliates and subsidiaries
companies. No part of this message or attachments may be used or reproduced in
any manner whatsoever.
--- End Message ---
--- Begin Message ---
BBC wrote:
Hi list..
Please any one point me to the web which talk about making transaction with
paypal step by step. Some body offered me the source
code and tutorial but until know he or she didn't send me.
http://www.paypal.com
I'm sure someone here has used / set up paypal but they provide complete
instructions on everything you need to do.
If you have any problems, that's what their support team is for.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
tedd wrote:
Hi gang:
From another list, a person posted:
"I want to use PHP's mb_substr() function to grab the first letter of a
UTF-8 encoded word (in Czech) being pulled out of MySQL. If I use the
plain substr()
the data gets garbled and I get a ? symbol in the browser.
My host says
that in order to get multibyte string functions I'd have to compile my own
copy of PHP. That's getting a little deeper than I want to for one function
on one page. Does anyone know what I could do as a workaround?"
I've tried to help, but it appears beyond me.
Anyone have any advice I could pass on?
"Out of luck".
mb_substr handles multibyte character sets, substr doesn't. Same as the
rest of the multibyte functions.
(Kinda like asking "I want to use all some of the GD functions but I
don't have GD - what can I do")..
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Hi all ,
I have array value as shown below, i have paste my test php code below:
I have problem when doing usort() when 'country' = '', i would like to
display records where country = '' last. Any ideas how to do that ?
Thanks
$arraytest= array(
array
(
'country' => '',
)
,
array
(
'country' => 'Thailand',
)
,
array
(
'country' => 'Singapore',
)
,
array
(
'country' => 'Singapore',
)
,
array
(
'country' => '',
)
,
array
(
'country' => '',
)
,
array
(
'country' => '',
)
);
function cmpcountry($a, $b)
{
$country1 = $a['country'];
$country2 = $b['country'];
return ($country1 < $country2) ? -1 : 1;
}
usort($arraytest,"cmpcountry");
while(list($name,$value)=each($arraytest)){
echo $name."<br><br>";
while(list($n,$v) = each($arraytest[$name])){
echo $v."<br><br>";
}
}
--- End Message ---