php - How to add Function on Onclick of a button in an echo? -


here function

    function addorder($name,$price){         echo $name." price: ".$price;         echo "<br>";         alert("function worked");     } 

and here echo

echo "<input type='button'value='add'class='btnadd'onclick=\'addorder("'.$row["name".'","'.$row["price"].'");\'>"; 

i have tried many solution in stackoverflow, function won't work when click add button

ok. clarify things 1 must know when newbie php , javascript.

so when hit php, generates output(for consider text). once php execution completes, output text sent browser. @ browser text interpreted html, javascript, , css. functioning trying achieve calling function on click of button, invoke function defined in javascript.

so php required generate javascript text include function (javascript method addorder) .

the exmple code below make 1 understand how works.

php code:

 ?> <input type="button" value='add' onclick='addorder("<?php echo $name; ?>","<?php echo $price; ?>");' />  <script type="text/javascript">      function addorder(name, price){              alert(name + ' : ' + price);      }  </script>  </body>  </html> 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -