Posted by Henk van Winkoop on 10/06/05 15:16
Hello Oli,
to your advice I replaced
alert('$MyTxt');
by:
alert('".$MyTxt."');
and it works.
Thanks.
Henk
"Oli Filth" <catch@olifilth.co.uk> schreef in bericht
news:1128597254.968555.120030@g44g2000cwa.googlegroups.com...
> Henk van Winkoop wrote:
> > How to show a PHP string value into a javascript alert box?
> >
> > function vMyMsgBox($MyTxt){
> > echo "
> > <script type = 'text/javascript'>
> > alert('$MyTxt');
> > ";
> >
> > vMyMsgBox("Show my text in the Alertbox"); //works fine
> >
> > $SomeText="Hello";
> > vMyMsgBox($SomeText); //does not work
> >
> > So when passing a string variable as function argument that function
> > argument variable is not accepted by javascript???
>
> You can't "pass" a variable from PHP to Javascript. All you can do is
> get PHP to print out a variable as a string within the JS script text,
> the same as you would print out a variable within the HTML text.
>
> So all you have to do is check what Javascript PHP is creating, i.e.
> View Source in your browser. Then go from there.
>
> --
> Oli
>
Navigation:
[Reply to this message]
|