Hi Steve,

What you're asking isn't possible.  Javascript runs client-side.  PHP runs
server-side.  You can't directly mix the two.

For example, you can use Javascript to respond when people choose menu
options, but you can't have Javascript communicate with PHP and pull
additional information from the database for your form.

You need to use a round-about approach.  Have Javascript reload the page
based on user input.  When the page is reloaded from the server, PHP can
process it (server-side).  PHP can add Javascript code / data to the page
arriving at the viewer's browser.  The Javascript runs and operates based on
this code / data.  Javascript passes information to PHP by posting forms or
including parameters in the url.

Here's another example...

You load a page for the first time...  PHP processes it...

if ($Name == "")
        $Name = "Brian";

echo "<script language='Javascript'>";
echo "\$Name = $Name;";
echo "</script>";



The page displays on the viewers browser and Javascript responds to user
form input.  Based on some action, Javascript reloads the page with the
following URL:

mytest.php?Name=John


Now PHP is receiving the variable Name and prints out different
JavaScript....


Does this make any sense?  I'm probably not sounding very clear... someone
help describe this, please =)

-Ed


> -----Original Message-----
> From: Steve Bradwell [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 13, 2002 11:35 AM
> To: 1LT John W. Holmes; Steve Bradwell; [EMAIL PROTECTED]
> Subject: RE: [PHP] confused newbie on PHP and Javascript.
> 
> 
> Hi thanks for the reply,
> 
> I do believe I understand what client side and server side really mean
> although I have much to learn, but is there a way to 
> accomplish what I'm
> trying to do? Maybe some kind of work around a person has 
> found when doing
> this kind of thing? 
> 
> Thanks again,
> 
> Steve
> 
> -----Original Message-----
> From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 13, 2002 2:26 PM
> To: Steve Bradwell; [EMAIL PROTECTED]
> Subject: Re: [PHP] confused newbie on PHP and Javascript.
> 
> 
> > I am having a problem, mostly concept wise of how, or if I 
> can use client
> > side Javascript in a server side php statement.
> 
> Do you know what client side and server side really mean??
> 
> For the function below...
> 
> > function Modify_Item_Details(){
> >
> > var test =
> > 
> document.forms[0].item.options[document.forms[0].item.selected
> Index].text;
> >
> > <?
> > $sql = "Select i.QTY_ON_HAND, u.UNIT from items i INNER JOIN";
> > $sql.= " units u ON i.Unit_Index = u.Unit_Index";
> > $sql.= " where i.Item_Index = '".echo "test\n"."'";
> >
> > $result = mysql_query($sql);
> >  while ($vars = mysql_fetch_array($result)){
> >    echo "document.forms[0].available.text='".$vars[0]."';";
> >    echo "document.forms[0].units.text='".$vars[0]."';";
> >  }
> > ?>
> > }//end Modify_Item Details
> 
> you do realize that the PHP runs first, on the server, 
> right?. The output is
> then sent to the client and the javascript is exectuted. You 
> can't mix the
> two. So, when you call that Javascript function, the PHP is 
> already done,
> it's not going to execute. Do a view source of your page...
> 
> You can send Javascript variables to PHP by submitting a form 
> or creating a
> URL to be clicked on. Either way, the page has to be 
> refreshed/submitted in
> order for PHP to recieve the variable.
> 
> You can send PHP variables to Javascript, too, but the PHP runs first.
> 
> <? echo "<script>var test = '$test';</script>"; ?>
> 
> ---John Holmes...
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
 
****************************************************************************
This message is intended for the sole use of the individual and entity to
whom it is addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law.  If you are
not the intended addressee, nor authorized to receive for the intended
addressee, you are hereby notified that you may not use, copy, disclose or
distribute to anyone the message or any information contained in the
message.  If you have received this message in error, please immediately
advise the sender by reply email and delete the message.  Thank you very
much.                                                                       

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to