Solved

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

Posted on 2008-10-17
4
1,769 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

705 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