Confirm Delete Not Work - php

i have one link for buy credit . i want when click on link confirm show so if user click yes link direct . but in my page when i click yes or no link direct me to href link . means yes or no not difrent and link work.
<script>
<!--
function confirmbuy() {
if (confirm("Are You Sure???")) {
return true;
} else {
return false;
}
}
//-->
</script>
Buy
i test this code for submit button and work propertly but for link not work !!!

Your event handler function (defined by the value of the intrinsic event attribute) doesn't return anything. It just calls confirmbuy and then stops.
If you want to return the return value of confirmbuy then you must do so explicitly:
onclick="return confirmbuy();">
You wouldn't have this problem is confirmbuy was the event handler:
ref_to_link.addEventListener('click', confirmbuy);
I recommend reading more about addEventListener and Unobtrusive Javascript.

You need to return the result of the confirmbuy() function, otherwise the event will never be cancelled.
Buy

Inline handlers are actually put into a function, which is set as the handler for the click event. So basically your code is equivalent to:
a.addEventListener("click",function(e){
confirmbuy();
})
As you can see, this handler does not return false, so the event progresses as normal.

you need:
onclick="return confirmbuy();"

better..
Buy

Fixed and removed unnecessary code:
Buy

Related

How to show a pop-up confirmation after clicking button

I'm still a learner on PHP.
I have a button, and it shall run a JavaScript after clicking it, but I want it to show an alert / pop up for users to confirm whether to continue or to abort.
Can I do the function in my PHP file in the button code?
<TD style='text-align:left;padding:0;margin:0;'>
<INPUT type='button' onmouseup="javascript:JS1();" value='JS1'></INPUT>
</TD>
you need to make function and use confirm();
<TD style='text-align:left;padding:0;margin:0;'>
<INPUT type='button' onmouseup="myFunction();" value='JS1'></INPUT>
</TD>
And
<script>
function myFunction() {
confirm("Please confrim");
}
</script>
Writing code is not what is supposed here.
But, still following pseudo code and concepts should work.
Steps:
If you are using jQuery, bind the event of click. If you are using core Javscript, use onclick attribute.
In the onclick function, add a confirmation popup.
confirm() returns true if user selects yes, or else it will return false.
Now, you have to proceed only if true is returned by confirm().
And javascript code:
<script>
function JS1() {
if (confirm('Your confirmation message')) {
// Write your code of form submit/button click handler.
}
else {
return false;
}
}
</script>
Have you tried bootstrap modal?
https://www.w3schools.com/bootstrap/bootstrap_modal.asp
https://getbootstrap.com/docs/4.0/components/modal/
https://getbootstrap.com/docs/3.3/javascript/
I have provided 3 links. I think these might help you a little. Do a research and it won't be very hard. Good luck.

Preventing href to move to header after action

I have this code
<a class ="hi" href='uselesslinkhere.php?page=page1&action=add&id=myid'>Add??</a>
Whenever a person clicks on this button, the link will act as if its a href=#.
Will using jQuery help? and if so, how does it work?
Thank guys!
Add a onclick event on anchor tag and stop page from following the href. Then change the content on your page through jQuery as you like and add the desired url through history.
<a class ="hi" onclick="loadPage(event,'uselesslinkhere.php?page=page1&action=add&id=myid')" href='uselesslinkhere.php?page=page1&action=add&id=myid'>Add??</a>
var loadPage = function(event,pageUrl){
event.preventDefault();
if(history && history.pushState)
{
history.pushState(null,null,pageUrl);
}
return false;
}

Disable submit button on click but after submission jQuery / PHP

At the moment I'm working on a project that requires the submission of a form for 'voting' for specific posts. At the moment clicking on the submit button works as it should, although if the button is clicked more than once, it does exactly that - submits the POST variables more than once causing them to be able to 'vote' for the item multiple times in one set of clicks.
I've looked at every jQuery code example I can find to solve this but nothing works. It works to disable the button, but after that the redirection page that grabs the data and runs the queries returns an error as nothing has been submitted. In short, it seems to disable the button but at the same time disable the information from being submitted.
Here's my jQuery code:
$('#vote').submit(function(){
$(this).children($btn).attr('disabled', true);
return true;
});
Any help would be great.
Thanks.
Use jquery .one
Description: Attach a handler to an event for the elements. The handler is executed at most once per element.
$(document).one("click","#vote",function(){
$(this).children($btn).attr('disabled', true);
return true;
});
Probably your best option is to only allow a single submission and adjust the button appearance some other way:
var submitted = false;
$('#vote').submit(function(){
if(submitted) {
// cancel additional submits
return false;
}
submitted = true;
$(this).children($btn).val('Please wait...');
});
you could add an click event. Instead of using submit button use a button click event.
the code might look like this
$($button).click(function(){
$(this).attr("disabled","disabled");
$($form).submit();
});
Jquery's on and off can be used here.
for example after submission,you can completely disable the click by
$('#vote').off('click');
and then switch it back if you want by
$('#vote').on('click');

need to disable jquery on click

I have the following html code
<div class='login'><a href='#'>Log in</a> to create custom dashboard</div>
This is my jquery code
$(".login").click(function() {
$(this).children('a').removeAttr("href");
$(this).attr('class','disabledlogin');
..............
}
So when I click on "Log in" link the dialog appears and I need to disable "Log in" link. But even if I change the class attribute I'm able to click and open another login dialog. What is the problem?
You can use .unbind() to unbind the event handler.
$(".login").click(function() {
$(this).children('a').removeAttr("href");
$(this).attr('class','disabledlogin');
// unbind the click handler. it should no longer fire.
$(this).unbind('click');
});
To revert, i.e. to add back the handler, you need to separate the handler into a function and bind it when needed using $(".login").click(onLinkClick);
function onLinkClick() {
$(this).children('a').removeAttr("href");
$(this).attr('class','disabledlogin');
// unbind the click handler. it should no longer fire.
$(this).unbind('click');
}
// call this initially for binding first time
// call this whenever you need to revert
$(".login").click(onLinkClick);
Use #techfoobar suggestion:
$(".login").click(function() {
$(this).children('a').removeAttr("href");
$(this).attr('class','disabledlogin');
// unbind the click handler. it should no longer fire.
$(this).unbind('click');
}

how to inactive a link using jquery

I have jQuery site here. I have 4 links with in ul tag. Within this link, I need to inactive a link but have to show. See below:
<div class="over hide" id="waterSecondOver">
Overview
Local Area
Floor Plans
<a href="javascript:void(0);" id="chancingallery" >Gallery</a>
</div>
I have a click function on the above links (except the 4th one i.e gallery). See the code
JQR('#waterSecondOver a').click(function() {
// my code
});
Here I need to show the gallery link, but nothing happens when click on the gallery (i.e must be inactive link or what I say it's functionality is only show the link as "gallery ")
I think it's clear . Please help me
JQR('#waterSecondOver a').click(function(event) {
event.preventDefault();
});
Don't set hrefs in the anchor tags to javascript:void(0); - this is messy because it's needless repetition. With jQuery, it's possible to use return false; in your event callback to avoid the default click event taking you to a new page or the current one. While this is the easiest method, it's not always the best. See this article for more info:
http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/
But you definitely don't want to be setting href manually.
I would simply change the class of the anchor(lets say class="active") and everytime onclick check for that "active" class. If the class is "active" do nothing else DO SOMETHING.
You can do this way for simplicity...
JQR('#waterSecondOver a').click(function(event) {
if(JQR(this).attr('id') == "chancingallery"){
// inactive all links except the one you dont want
}else{
// whatever you need....
}
});

Categories