Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  96] [ 2]  / answers: 1 / hits: 22107  / 11 Years ago, sun, april 28, 2013, 12:00:00

I am having a problem with onclick function integrating it with php .Can someone please help



Below is my codes



<html>
<head>
<title></title>
<script language=Javascript>
function delete()
{
val del=confirm(Do you wanto delete the player?);
if(del==true)
{
alert(player Deleted);
}
else
{
alert(record not deleted);
}
return del;
}
</script>
</head>
<?php
Echo “
<a href='delete.php?player_id=$player_id' onclick='delete()'>Delete</a>”
?>

More From » php

 Answers
9

I found a pretty good solution. However, It adds a little extra to your code. I do not recommend using this method too much. I am a new PHP developer, so there are probably somethings this method can and cannot do.



also I cannot seem to prevent this method from loading a new page, so the best way is to add your php to the beginning of the file. This is also a better solution for using AJAX (my opinion)



if the current file is index.php...



make a form tag element






'<form action=index.php method=post>'

'<input type=submit name=helloWorld value=hello World>'

'</form>'





here you will display the content of what you are trying for, with a click






'<article>'

'<?php echo myFunction(); ?>'

'</article>'





this next php markup can go anywhere as long as it it is in the same file... Unless you know how to work around. Best place is before the HTML.






'<?php '
'function myFunciton() {'
'if (isset($_POST[helloWorld])) {'
'echo hello world; ... your methods'
'}'
'}'





or you could directly access it without using a function



<body>
<form action=index.php method=post>
<input type=submit name=hello value=hello>
<input type=submit name=goodBye value=goodBye>
</form>
<article>
<?php
if (isset($_POST[hello])) {
echo This happens if you click hello;
}
if (isset($_POST[goodBye])) {
echo This happens if you click goodBye;
}
?>
</article>
</body>

[#78553] Saturday, April 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
orlando

Total Points: 413
Total Questions: 92
Total Answers: 96

Location: Mauritania
Member since Sun, Oct 17, 2021
3 Years ago
;