I'm wanting to popup a confirm/cancel div in which I can style when my users click the delete button in my feed. But what I have isn't working. And I'm wondering if its because I don't have anything in delete.php to tell it to direct it into a popup. It just goes to the delete.php page atm. Could someone give me some direction please?
Javascript:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/JavaScript">
function confirmDelete(){
var agree=confirm("Are you sure you want to delete this file?");
if (agree)
return true ;
else
return false ;
}
</script>
Button:
echo 'X ';
You need to return the value returned by confirmDelete.
The attribute is onclick, not onClick.
The attribute is missing a closing quote.
JavaScript
function confirmDelete(){
return confirm("Are you sure you want to delete this file?");
}
PHP
echo '<a ... onclick="return confirmDelete();" ...';
That said, it looks like you're using jQuery (albeit a super old version). If that's really the case, use jQuery and start writing unobtrusive JavaScript already.
$(function ()
{
$('a.delete').click(confirmDelete);
});
Get yourself a reasonably recent version of jQuery as well.
This doens't regards jQuery but anyway you could do in this way:
<script>
function confirmDelete(idPassed){
if (confirm("Are you sure you want to delete this file?"))
window.location = "mysite/raw/sn-extend/theme/default/delete.php?id=" + idPassed;
}
</script>
X
Related
Please bear with me but I was giving some code to launch a lighbox. I need to display a lightbox when a user clicks on my link. The lightbox coded is in place already and is launched using a unique id. My example below uses (1111)
<script src="bootstrap.js" type="text/javascript"></script>
<script type="text/javascript">
lightbox = new fusepump.lightbox.buynow(1111);
var callToActionElement = document.getElementById( "unique-btn");
callToActionElement.addEventListener("click", function()
{ lightbox.show(); //Show the lightbox } );
</script>
My link code is:
Buy
For some reason it's not working. I think that the syntax is wrong.
EDIT: you commented out the last part of your code //Show the lightbox } );
The brackets never get closed and the semicolon won't be at the end of your code but in the comment. Make the comment like this /*Show the lightbox*/
You can also set an onClick attribute in which you can call the function name of your javascript function. It will look like this:
Buy
I have a php file which is part of a basic Content Management System. Inside this file I have a table which contains a "Delete" link in every row.
What I am trying to do is create a choice popup in a javascript function of which I call when the link is clicked.
My function code (which appears in the head part of my php file) is below:
<script type="text/javascript">
function delete(skillID)
{
var answer = confirm("Are you sure you want to delete this record?");
if(answer == true)
{
window.location.href = "process/deleteRecord.php?skillID=" + skillID;
}
}
The code which calls this function is below:
echo "<td>Delete</td>";
The problem is that the box doesn't even popup, so the function isn't called properly.
Can anyone help?
If there are any other details you need to know please let me know.
You can try something else :
echo "<td>Delete</td>";
You need to use the "onClick" attribute, try that :
echo "<td>Delete</td>";
Hope it'll help!
I echo a button from a php script as following: print'<button id="testingbtn">TEsting</button>';
I use the id listen to the button and alert a notification message as following:
$('#testingbtn').click(function(){
alert('working');
});
The thing is that i used the same method before and it worked for me on all browsers but not anymore. can someone try to help me out the problem.
thanks guys..
Try this, we assuming your 'testingbtn' is dynamically added to the screen.
$(document).ready(function(){
$( "body" ).on( "click", "#testingbtn", function() {
alert('working');
});
});
I never recommend to do it in this way. Always put this code outside php.
HTML
<button id="testingbtn">TEsting</button>;
jQuery
$('#testingbtn').click(function(){
alert('working');
});
Also make sure jQuery is included in your code.
Point 1: Check whether you have included the jquery library or not.
Point 2: [If point 1 is OK], Where have you put your script? If you put your script before button code, than use document ready function
$(document).ready(function(){
$('#testingbtn').click(function(){
alert('working');
});
});
Alternately, if you want to put your code unchanged, than place your script after your button code[best practice: put them at the bottom of the page].
I don't use print. I always use echo to show it in my html page.
<?php
echo '<button id="testingbtn">TEsting</button>';
?>
In jquery:
$('#testingbtn').click(function(){
alert('working!');
});
Try reading this
I am trying to create a link in JS that moves the person the page from where he has come from. Here is the code.
<script language="javascript">
function Jump()
{
document.href=document.referrer;
}
</script>
Here is the html,
Skip and Continue
Now when the user clicks on the link, nothing happens. Please guide me where I am doing wrong. Thanks
how about using the below code to move back
history.back();
Many browsers will not use document.referrer for privacy reasons, especially if the referrer is from another domain.
Instead, try onclick="history.go(-1)" instead of your Jump() function.
It is better to bind a click listener than use onclick.
Try changing it to this:
<a id="myLink" href="#">Skip and Continue</a>
And Javascript:
<script type="text/javascript">
document.getElementById('myLink').addEventListener('click', function(e) {
e.preventDefault();
document.location.href=document.referrer; //actually better as "history.back()"
}
</script>
It is not document.href but window.location.href...
<script>
function Jump(){
if(document.referrer)location.href=document.referrer;
else history.back();
}
</script>
(If you used the jump to get to the current page, there is no referrer.)
i want run a php code when a user click a link and change temporarily value of link with output returned by script without reloading page and redirect user to another page
for example if a users click on button :
Click Me!
a code php run for example script.php
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
$.get("script.php");
return false;
}
</script>
Click Me!
for example if output of script( $result ) is: 30
then 30 will replaces button: "Click Me!" without reloading page
so at the end after the script is executed i have temporarily instead of "Click Me!" number 30 and if is possible also add a animation gif or something of similar so as: wait wait blinking during execution of script
thanks
Try this, create a class with two methods uW (user wait) uWC (user wait cancel). This class can be reused for future as well
var Util = {
uW:function(id) {
$("#"+id).html("<img src='path to animation GIF' />");
},
uWC:function(id,data) {
$("#"+id).html(data) ;
}
}
Now your function will looks like this
function doSomething() {
Util.uW('clickme'); // clickme is ID of your anchor tag
$.ajax({
url: "script.php",
context: document.body,
success: function(data ){
Util.uWC('clickme',data );
}
});
This might be what you are looking for. I am guessing you want to replace Click Me! with the value returned(30). If not, you can user data inside the function to replace whatever u want
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
$el=$(this);
$.get("script.php",function(data){$el.html(data)});
return false;
}
</script>
Click Me!
Click Me!
And the javascript code:
$(function(){
$('#clickme').click(function(){
$(this).load('script.php');
return false;
});
});
You almost have your answers in your question. Use ajax. http://www.w3schools.com/ajax/default.asp you are also using jquery. Jquery has excellent documentation on ajax