0

Here is my link with embedded js

<a style="padding: 5px;" onclick="confirm_message(); $('contact_693_').show(); $('errors_693_').hide(); this.hide(); $('dont_693_').show();; return false;" id="the_link_693_" href="#" class="add_someone_else">Check it out</a>

And here is my function

function confirm_message(){
         var response = confirm("Are you sure?");
    if(response){
      return false;
    }else{
             return false;
        }
}

Basically I dont want any of the other js to fire if the user clicks no in the confirm....but all the other javascript

  $('contact_693_').show(); $('errors_693_').hide(); this.hide(); $('dont_693_').show();; return false;"

still fires whether the user clicks yes or no in the confirm...any ideas on how to fix this....

Also this embedded js was not created by me and is built on the page with ruby...

1
  • Can you post the ruby code that produces this? Is it Rails? Commented Apr 27, 2012 at 1:49

2 Answers 2

3

Throw an error, like this:

function confirm_message(){
    var response = confirm("Are you sure?");
    if(response){
      return false;
    }else{
         throw new Error("Chuck Norris roundhouse kicked your JS, sorry."); // or something a little more descriptive
    }
}

It's not pretty but it should stop all future JS from processing.

Sign up to request clarification or add additional context in comments.

2 Comments

how would throwing an error help the user....i just want the box to close and the other js not to fire.
@Matt: Throwing an error will cause all other Javascript on the page to cease executing. That includes 'the other js'.
2

Include your code in the confirm function:

function confirm_then_execute(){    
     var response = confirm("Are you sure?");    
     if(response){
         $('contact_693_').show(); $('errors_693_').hide();this.hide(); $('dont_693_').show();return false;"
     }
     else{    
         return false;    
    }
}

html:

<a style="padding: 5px;" onclick="confirm_then_execute()" id="the_link_693_" href="#" class="add_someone_else">Check it out</a>                 

2 Comments

i cant do that because i dont have those div ids and class on the js level
How about passing the ids as arguments: confirm_then_execute(id1,id2)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.