/    Sign up×
Community /Pin to ProfileBookmark

How to add CONFIRM popup window,for a url link with onclick event?

Hi I am one of teh newbee to programming. I am trying to use “onclick” event on a url as below.

[CODE]
<li><a href onclick=”javascript:callConfirm();”>Add a Project</a></li>
[/CODE]

And my java function in a file which is included in the above jsp file look as below:

[CODE]
function callConfirm(){
var answer = confirm(“Accept or Decline”);
if(answer){
window.location ='<a href=/admin/addProject></a>’;
}
else {
window.location ='<a href=/></a>’;
}
}
[/CODE]

I even tried with giving a location (window.location) as “http:www.google.com”;

Both of them are not working but when I click my url(Add a Project) I am getting a confirmation window. But after that it is not not relocating to respective pages. Please tell me where I went wrong?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@DetectAug 03.2007 — window.location = 'http://www.google.com';
Copy linkTweet thisAlerts:
@Lilly07authorAug 04.2007 — window.location = 'http://www.google.com';[/QUOTE]

I did try with single quotes too. But the browser is not getting redirected to google page. I have no idea why this simple task is not taking place ? I am using Spring and hibernate to build my web application. Any thing wrong in my function?
Copy linkTweet thisAlerts:
@Declan1991Aug 04.2007 — I would write:
<i>
</i>function callConfirm(){
var answer = confirm("Accept or Decline");
if(answer){
window.location ='/admin/addProject';
}
else {
window.location ='';
}
}


What is the second one trying to direct to? You don't write an anchor tag, you just let window.location equal to the url.
Copy linkTweet thisAlerts:
@Lilly07authorAug 06.2007 — I would write:
<i>
</i>function callConfirm(){
var answer = confirm("Accept or Decline");
if(answer){
window.location ='/admin/addProject';
}
else {
window.location ='';
}
}


What is the second one trying to direct to? You don't write an anchor tag, you just let window.location equal to the url.[/QUOTE]


Thanks for your response. The second one is trying to redirect to the home page '/'. But still I did try your suggestion without using <a href..> But still it is not redirecting to respective pages.. ?
Copy linkTweet thisAlerts:
@Lilly07authorAug 06.2007 — 
  • 1. Yes, sorry for the confusion. It is working perfectly fine and the problem was due to browser compatibility. The above code works perfect in IE whereas not working(ie redirecting) in Firefox. Is there anyway to solve this problem.


  • 2. Again in IE for the code below, I am not seeing any line under "Add Project" but onclick event works. How to rectify this problem.
    [CODE]<a href onclick="javascript:callConfirm();">Add Project</a>[/CODE]


  • Thanks and Regards

    Lilly
    Copy linkTweet thisAlerts:
    @DetectAug 06.2007 — href="#"
    Copy linkTweet thisAlerts:
    @Lilly07authorAug 06.2007 — href="#"[/QUOTE]

    [CODE]<a href="javascript:callConfirm();">Add Project</a>[/CODE]
    Yes Thanks and I did solve that problem as above mentioned. But still I don't know how to solve the browser compatibility problem. It is working perfect in IE but not in Mozilla Firefox ?
    ×

    Success!

    Help @Lilly07 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...