Problem
When i click this link its alert won't open what should I do ?
My Code
echo "<td><a href='#' onClick='alert('Not an Enumerator!')'>Location</a></td>";
You have to escape quotes \' when necessary, try this:
echo '<td>Location</td>';
Try By Following Example.
<a href="#" onClick='alert("Not an Enumerator!")'>Location</a>
Don't Use Single quote inside alert
Try below example you can do both alert and onclick or either based on return type of function called on click.
<?php
echo "<td><a href='test.php' onclick='return test_click();'>Location</a></td>";
?>
<script type="text/javascript">
function test_click(event){
alert("Inside this function");
return true;
}
</script>
Related
When I click on the post it opens a random post instead of the post I clicked.
The $postid = get_the_ID(); is in the beginning of my code.
Here's the function i use inside the onlick='' that is inside the <a> tag which is around the post image
<script type="text/javascript">
function wholeAd(){
var permalink = '<?php echo get_permalink($postid); ?>';
window.open(permalink, 'newwindow', 'width=900, height=650');
return false;
}
</script>
<div class="ad-box span3">
<a class="ad-image" onclick='wholeAd()'>
For Popup you can use something like this
"<a href='javascript:OpenPopUpPageWithTitle('"+oListItem.get_item('Url').get_url()+"', 'NotificationCallback', "+oListItem.get_item('Width')+", "+oListItem.get_item('Height')+",'" + oListItem.get_item('Title') + "');'> " + oListItem.get_item('Title') + "</a>"
for New Window you can use something like this
<a target='_blank' href='url' style='styles'>Title</a>
Hope this helps, Mark it as answer if it solves your query
Here is the solution:
You don't have to make a function
<a href="<?php the_permalink(); ?>" onclick="window.open(this.href,'newwindow', 'width=900, height=650');return false;">
I have this code inside a while loop for fetching data from the database. I want to show a confirmation popup when the Delete link is clicked.
echo "<td><a href='delete.php?id=" . $row['serial_no'] . "'>Delete</a></td>";
How can this be done?
Try out confirm function from JavaScript, learn jQuery as fast as possible and try to seperate javascript from html ;).
http://www.w3schools.com/jsref/met_win_confirm.asp
<td>
<a href="delete.php?id=<?php echo $row['serial_no'] ?>" id="a_id">
Delete
</a>
</td>
<script type="text/javascript">
$(function() {
$('td a#a_id').click(function() {
return confirm("Are You sure that You want to delete this?");
});
});
</script>
add onClick attribute for anchor link and call the function on it. Or simply show confirm.
<a onClick = "confirm ('Are You Sure?')"
Complete Example
function disp_confirm()
{
var r=confirm("Press a button!")
if (r==true)
{
alert("You pressed OK!")
}
else
{
alert("You pressed Cancel!")
}
}
<a onclick="disp_confirm()"
try this
function DeleteClick(serial_no)
{
if(confirm('Are you sure to delete ' + serial_no + '?'))
{
alert('Data deleted');
return true;
}
return false;
}
echo "<td><a href='delete.php?id=" . $row['serial_no'] . "' onclick="return
DeleteClick(\''. $row['serial_no'].'\')">Delete</a></td>";
echo "<td>Delete</td>";
try this code,hope it will work-
<td>
<a href="#" onclick="conf("delete.php?id=".<?php echo $row['serial_no']; ?>.")">
Delete
</a>
</td>
<script type="text/javascript">
function conf(str) {
if(confirm("Your Message") == true){ location.replace(str);}
}
</script>
and in the delete.php page-just grab the id from url and run the delete query.
I'm trying to put popup message in this code before user delete data. Here is my code.
while ($test = mysql_fetch_array($result))
{
$id = $test['FailID'];
echo "<tr align='center'>";
echo"<td><font color='black'>" .$test['FailID']."</font></td>";
echo"<td><font color='black'>" .$test['TajukFail']."</font></td>";
echo"<td><font color='black'>". $test['JilidFail']. "</font></td>";
echo"<td><font color='black'>". $test['StatusFail']. "</font></td>";
echo"<td> <a href ='daftarkemaskini.php?FailID=$id'>Edit</a>";
echo"<td> <a href ='padamfail.php?FailID=$id'><center>Delete</center></a>";
echo "</tr>";
}
but when I put it in there it doesnt work at all.
echo"<td> <a href ='padamfail.php?FailID=$id' onClick="return confirm('are you sure you want to delete??');"><center>Delete</center></";>"
Can anyone help me on this?
You need to escape the double quotes. Your code also had another syntax error at the end.
echo "<td> <a href='padamfail.php?FailID=$id' onClick=\"return
confirm('are you sure you want to delete??');\"><center>Delete</center></a>";
You are putting javascript onclick code inside a double quote, which is being used to terminate the echo. Escape the double quotes:
echo"<td> <center>Delete</center>"
You can try this--
echo "<td> <a href ='padamfail.php?FailID=$id' onClick=return confirm('are you sure you want to delete??');><center>Delete</center></;>";
Try to escape the string:
echo "<td> <a href ='padamfail.php?FailID=$id' onClick=\"return confirm('are you sure you want to delete??');\"><center>Delete</center></";>"
<div class="third">
<input type="button" value="Remove" class="remve" name="<?php echo $row['choice_id']; ?>" onClick="deleteImage(<?php echo $row['choice_id']; ?>)"style="cursor:pointer;">
</div>
<script type="text/javascript">
function deleteImage(x){
var conf = confirm("Are you sure you want to delete this choice?");
if(conf == true){
window.location = "addnewentry/choiceRemove.php?id="+x;
}
}
</script>
Please the change the line
echo"<td> <a href ='padamfail.php?FailID=$id' onClick="return confirm('are you sure you want to delete??');"><center>Delete</center></";>"
to
echo "<td> <a href ='padamfail.php?FailID=$id' onClick='return confirm('are you sure you want to delete??');' ><center>Delete</center></a>";
echo"<td><a href='delete.php?id={$row['id']}' onclick='return confirm_alert(this);' >Delete</a></td>";
**you should try this code ,it will definitely work **
=
<script>
//alert on delete
function confirm_alert(node) {
return confirm("You are about to permanently delete a product. Click OK to continue or CANCEL to quit.");
}
</script>
<script>
//alert on delete
function confirm_alert(node) {
return confirm("You are about to permanently delete a product. Click OK to continue or CANCEL to quit.");
}
</script>
hoping this will help you
I have a php function:
function myfunc() {
//then I have a div...
echo '<div class="overlay">';
echo "<button onclick=\"$('.overlay').hide();\">Close</button>";
echo '</div>';
}
My problem is that when I click on the close button the div is not hiding.
What I'm I doing wrong here?
Avoid to hardcode javascript handlers and inline events inside the output of php code: do instead
echo '<div class="overlay">';
echo "<button>Close</button>";
echo '</div>';
and previously insert in your page this code that detects a click on your button using event delegation
<script>
$(document).on('click', '.overlay button', function() {
$(this).parent().hide()
});
</script>
try:
<button onclick="this.parentNode.style.display = 'none'; return false;">Close</button>
Try this code:
function myfunc() {
//then I have a div...
echo '<div class="overlay" id="overlay" >';
echo "<button onclick=\"hide()\">Close</button>";
echo '</div>';
}
//using the javascript code:
function hide()
{
document.getElementById("overlay").style.display="none";
}
try:
$('.overlay button').live('click',function(
$('.overlay').css({'display': 'none'});
));
Why is it that my onClick won't work?
When I click I get an error message like this:
syntax error : identifier starts immediately after numeric literal
It will not determine the ID from the database, the database ID is varchar(50).
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].")'></a>
<script type="text/javascript">
function delete_Affiliate(id){
alert(id);
}
</script>
Try this:
delete_Affiliate(" <?php echo $row['affiliateid']; ?>")
That is, you need to echo the value from PHP.
Try this
<script type="text/javascript">
function delete_Affiliate(id){
alert(id);
}
Can you please post your PHP script ?
You should have something like :
<?php
echo "<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(\"".$row['affiliateid']."\");return false;'></a>
<script type='text/javascript'>
function delete_Affiliate(id){
alert(id);
}
</script>";
?>
try this :
<?php
echo "<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].");'></a>";
?>
or this :
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid'] ?>");'></a>
you have to add php tag and echo statement between your anchor tag like this
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a>
you didn't add this
<?php echo $row['affiliateid']; ?>
in your anchor tag so just add it and check it out.
I hope it will help you
Try this
delete_Affiliate(<?php echo $row['affiliateid']; ?>);
there may be issue on this line
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].")'></a>
it should be
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a>
Use this code, hope it will work