Solved

Need to add confirm (Yes or No) prompt to javascript function

Posted on 2008-10-17
4
1,763 Views
Last Modified: 2012-05-05
I need to update the following javascript function with a confirm dialog (ie: Yes or No prompt):

-----------------------------------------------------------------------------------------------------------------

// BetterInnerHTML v1.15 - by Craig Buckler, http://www.optimalworks.net/
function BetterInnerHTML(_1,_2,_3){function Load(_4){var _5;if(typeof DOMParser!="undefined"){_5=(new DOMParser()).parseFromString(_4,"application/xml");}else{var _6=["MSXML2.DOMDocument","MSXML.DOMDocument","Microsoft.XMLDOM"];for(var i=0;i<_6.length&&!_5;i++){try{_5=new ActiveXObject(_6[i]);_5.loadXML(_4);}catch(e){}}}return _5;}function Copy(_8,_9,_a){if(typeof _a=="undefined"){_a=1;}if(_a>1){if(_9.nodeType==1){var _b=document.createElement(_9.nodeName);for(var a=0,attr=_9.attributes.length;a<attr;a++){var _d=_9.attributes[a].name,aValue=_9.attributes[a].value,evt=(_d.substr(0,2)=="on");if(!evt){switch(_d){case "class":_b.className=aValue;break;case "for":_b.htmlFor=aValue;break;default:_b.setAttribute(_d,aValue);}}}_8=_8.appendChild(_b);if(evt){_8[_d]=function(){eval(aValue);};}}else{if(_9.nodeType==3){var _e=(_9.nodeValue?_9.nodeValue:"");var _f=_e.replace(/^\s*|\s*$/g,"");if(_f.length<7||(_f.indexOf("<!--")!=0&&_f.indexOf("-->")!=(_f.length-3))){_8.appendChild(document.createTextNode(_e));}}}}for(var i=0,j=_9.childNodes.length;i<j;i++){Copy(_8,_9.childNodes[i],_a+1);}}_2="<root>"+_2+"</root>";var _11=Load(_2);if(_1&&_11){if(_3!=false){while(_1.lastChild){_1.removeChild(_1.lastChild);}}Copy(_1,_11.documentElement);}}

-----------------------------------------------------------------------------------------------------------------

How would I do that?  Also, ... how would I update the link that triggers the function? :

<a href='javascript:BetterInnerHTML(document.getElementById("narrative"),"Text to be inserted");'>Insert</a>

Please advise.

Thanks,
- Yvan
0
Comment
Question by:egoselfaxis
  • 2
4 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22740425
I would start my first uncompacting javascript so i could see it clearly...all the line spaces have been removed...but the code is still the same.
0
 

Author Comment

by:egoselfaxis
ID: 22740482
Sorry - the library is not available in an uncompressed format.

http://www.optimalworks.net/resources/betterinnerhtml/

0
 
LVL 15

Accepted Solution

by:
MMDeveloper earned 500 total points
ID: 22740940
instead of trying to uncompress that.. try this


<a href='javascript:BetterInnerHTML_confirm(document.getElementById("narrative"),"Text to be inserted");'>Insert</a>


and the relevant JS
function BetterInnerHTML_confirm(_1, _2, _3) {
      message = "Are you sure?";
      response = confirm(message);
      
      if (response) {
            BetterInnerHTML(_1, _2, _3);
      }
      else {
            alert("canceled");
      }
}
0
 

Author Comment

by:egoselfaxis
ID: 22741648
Ah .. there we go. That worked great.

Thanks so much!

- Yvan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now