Jump to content

will it work?


riddhi

Recommended Posts

I am getting error not sure it is problem in code or that php cannot be embedded in javascript.

 

echo "<script type='text/javascript'>";
  echo "function process() {";
  echo "<?";          // starts the PHP code here 
  echo "for($i=0; $i < count($productId); $i++) {";
  echo "$_GET['p']=$productId[$i]";
  echo "addToCart()";
  echo "}";
  echo "?>";
  echo "$_GET['action']='view'"; // Passes it on to cart.php
  echo "}";
  echo "</script>";
  
  echo "<br /><br />";
      echo " <div align='right'> ";
      echo "<form name='form1' method='get' action='cart.php?action=view'onSubmit='process()'>";
      echo "<input name='cart' type='submit' value='Add To Cart' />";
  echo "</form>";
  echo "</div>";

Link to comment
https://forums.phpfreaks.com/topic/48227-will-it-work/
Share on other sites

no, you can't embed php in javascript like that.. I'd suggest you read up on how php works. (I haven't read the content on that link, it was just a google search) After you have some idea how it works then you can refine your script to work how you want it...

 

PS. There is a way to send requests to a php script via javascript (ajax) but I'd suggest reading up on how php works so you understand what it going on.

Link to comment
https://forums.phpfreaks.com/topic/48227-will-it-work/#findComment-235767
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.