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
Post a Comment