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...
asked Apr 27, 2012 at 1:43
Matt Elhotiby
44.2k91 gold badges226 silver badges329 bronze badges
-
Can you post the ruby code that produces this? Is it Rails?andrewdotnich– andrewdotnich2012年04月27日 01:49:29 +00:00Commented Apr 27, 2012 at 1:49
2 Answers 2
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.
answered Apr 27, 2012 at 1:52
Elliot Bonneville
53.6k24 gold badges101 silver badges125 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Matt Elhotiby
how would throwing an error help the user....i just want the box to close and the other js not to fire.
Elliot Bonneville
@Matt: Throwing an error will cause all other Javascript on the page to cease executing. That includes 'the other js'.
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>
answered Apr 27, 2012 at 1:54
Christophe
28.3k29 gold badges105 silver badges145 bronze badges
2 Comments
Matt Elhotiby
i cant do that because i dont have those div ids and class on the js level
Christophe
How about passing the ids as arguments: confirm_then_execute(id1,id2)?
lang-js