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
Add a ment  | 

4 Answers 4

Reset to default 2

If 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
Add a ment  | 

4 Answers 4

Reset to default 2

If 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