admin管理员组文章数量:1026989
with the use of <a>
tag, i can put like:
<a href="include/sendemail.php?id_user=<?= $_GET['id_user'];?>" onclick="return confirm('Are you sure want to send an email?');" >Send Email</a>
and how do apply that code to button :
<input type="button" onclick="return confirm('Are you sure want to send an email?');" value="Send Email" >
with the use of <a>
tag, i can put like:
<a href="include/sendemail.php?id_user=<?= $_GET['id_user'];?>" onclick="return confirm('Are you sure want to send an email?');" >Send Email</a>
and how do apply that code to button :
<input type="button" onclick="return confirm('Are you sure want to send an email?');" value="Send Email" >
Share
Improve this question
edited Mar 14, 2011 at 11:14
ThiefMaster
319k85 gold badges607 silver badges646 bronze badges
asked Mar 14, 2011 at 11:13
tonoslfxtonoslfx
3,43216 gold badges68 silver badges107 bronze badges
4
- What you have will work. What is it doing/not doing that you don't expect? – T.J. Crowder Commented Mar 14, 2011 at 11:16
- (sidenote) Event attributes are considered bad practise. Try to make them unobtrusive instead. – Gordon Commented Mar 14, 2011 at 11:21
- Did you manage to solve the problem? – Michiel Pater Commented Mar 14, 2011 at 11:21
- @Michiel Pater yes thanks for everyone :) – tonoslfx Commented Mar 14, 2011 at 11:24
4 Answers
Reset to default 2If you would like achieve your goal with only a little change, try something like this:
<input type="button" onclick="if(confirm('Are you sure want to send an email?')) { document.location.href = 'include/sendemail.php?id_user='; } " value="Send Email" />
<input type="button" onclick="return myFunc();" value="Send Email" >
<script>
function myFunc()
{
var flag = confirm('Are you sure want to send an email?');
if(flag)
document.location.href = "include/sendemail.php?id_user=<?= $_GET['id_user'];?>" ;
else
return false;
}
Buttons are not hyperlinks.
To make a button navigate to a different page, you can write location = 'URL';
in the click
handler.
<form action="include/sendemail.php" method="GET">
<input type="hidden" name="id_user" value="<?php echo intval($_GET['id_user']); ?>" />
<input type="button" onclick="return confirm('Are you sure want to send an email?');" value="Send Email" />
</form>
You could also use onsubmit
of the <form>
tag.
with the use of <a>
tag, i can put like:
<a href="include/sendemail.php?id_user=<?= $_GET['id_user'];?>" onclick="return confirm('Are you sure want to send an email?');" >Send Email</a>
and how do apply that code to button :
<input type="button" onclick="return confirm('Are you sure want to send an email?');" value="Send Email" >
with the use of <a>
tag, i can put like:
<a href="include/sendemail.php?id_user=<?= $_GET['id_user'];?>" onclick="return confirm('Are you sure want to send an email?');" >Send Email</a>
and how do apply that code to button :
<input type="button" onclick="return confirm('Are you sure want to send an email?');" value="Send Email" >
Share
Improve this question
edited Mar 14, 2011 at 11:14
ThiefMaster
319k85 gold badges607 silver badges646 bronze badges
asked Mar 14, 2011 at 11:13
tonoslfxtonoslfx
3,43216 gold badges68 silver badges107 bronze badges
4
- What you have will work. What is it doing/not doing that you don't expect? – T.J. Crowder Commented Mar 14, 2011 at 11:16
- (sidenote) Event attributes are considered bad practise. Try to make them unobtrusive instead. – Gordon Commented Mar 14, 2011 at 11:21
- Did you manage to solve the problem? – Michiel Pater Commented Mar 14, 2011 at 11:21
- @Michiel Pater yes thanks for everyone :) – tonoslfx Commented Mar 14, 2011 at 11:24
4 Answers
Reset to default 2If you would like achieve your goal with only a little change, try something like this:
<input type="button" onclick="if(confirm('Are you sure want to send an email?')) { document.location.href = 'include/sendemail.php?id_user='; } " value="Send Email" />
<input type="button" onclick="return myFunc();" value="Send Email" >
<script>
function myFunc()
{
var flag = confirm('Are you sure want to send an email?');
if(flag)
document.location.href = "include/sendemail.php?id_user=<?= $_GET['id_user'];?>" ;
else
return false;
}
Buttons are not hyperlinks.
To make a button navigate to a different page, you can write location = 'URL';
in the click
handler.
<form action="include/sendemail.php" method="GET">
<input type="hidden" name="id_user" value="<?php echo intval($_GET['id_user']); ?>" />
<input type="button" onclick="return confirm('Are you sure want to send an email?');" value="Send Email" />
</form>
You could also use onsubmit
of the <form>
tag.
本文标签: phpJavaScript onClick hrefStack Overflow
版权声明:本文标题:php - JavaScript onClick href - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745559024a2156048.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论