Solved

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

Posted on 2008-10-17
4
1,766 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

679 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