www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25

Thread: Help Passing Variables to/from Popup Window

  1. #16
    Join Date
    May 2014
    Posts
    834
    swap out the alert for whatever function you want it to call... pretty simple. You can put any function as the final parameter of the confirm function.

    Code:
    confirm(
    	'Accept Paypal Surcharge?', 
    	'<p>There will be a ' + rate + '% surcharge for using PayPal.</p><p><span class="keepTogether"><b>Product Total:</b> $' + total.toFixed(2) + '</span> &bull; <span class="keepTogether"><b>Total Charge:</b> $' + (total * (rate + 100) / 100).toFixed(2) + '</b></span></p><p>Please click the Accept button to authorize this charge.<br />Otherwise click the Decline button.</p>',
    	alert
    );
    Just replace 'alert' with whatever function you want to handle the result. Because of how it (or window.open if you went that route) works, you can' t simply 'wait for a result'; the joys of event driven programming.
    Java is to JavaScript as Ham is to Hamburger.

  2. #17
    Join Date
    Apr 2013
    Posts
    21
    Got it! Thanks. Works fine now. Appreciate all your help.

  3. #18
    Join Date
    Apr 2013
    Posts
    21
    BTW, what's the purpose of the two 'true' parameters at the end of the handlerAdd function?

  4. #19
    Join Date
    May 2014
    Posts
    834
    Oops, you can lose those, that's left-over from when it was using my library. In the library the first one prevents event bubbling, the second one calls a code to make sure nothing gets selected accidentally.

    http://www.elementalsjs.com/Element.handlerAdd

    The standalone version is far simpler because it doesn't add a wrapping function to automatically do those, or do the e = e || window.event; var t = e.target || e.srcElement for you.
    Java is to JavaScript as Ham is to Hamburger.

  5. #20
    Join Date
    Apr 2013
    Posts
    21
    Thanks, I was just wondering. Actually, I had hoped that they somehow controlled the buttons so I could use it as a more generic routine (a customized alert besides a customized confirm). Oh well, you can't have everything.

    Again, my thanks for your help.
    BK

  6. #21
    Join Date
    May 2014
    Posts
    834
    I was actually thinking along those lines -- expanding that code to let you specify a list of buttons, returning that button's text as the result instead of true/false.

    something like:

    dialogBox = function(title, message, buttons, handler)

    where buttons is an array of texts to put into the buttons. Might be even better to just pass it a single object:

    dialogBox = function(data)

    Where:

    Code:
    var data = {
    	title : 'dialog title',
    	message : '<p>Your message markup</p>',
    	buttons : [ 'Yes', 'No', 'Cancel' ],
    	resultFunction
    };
    The object would be passed by reference lowering the memory use (in theory) and would be a bit clearer as to what's being declared for values.

    I might spend the time to put that together working as it could be useful for some of the stuff I'm working on as well -- both as a standalone, and as an example for my JavaScript library. I've got to fix the bugs my taking bad advice introduced to my library first, but when I get the more versatile version of this up and running I'll post a link to it here.

    I've also been playing with the idea of a full-on browser based windowing UI API, just for 'laughs'. Well, not entirely for laughs - I have an... odd idea I've been playing with.
    Last edited by deathshadow; 05-16-2014 at 10:26 AM.
    Java is to JavaScript as Ham is to Hamburger.

  7. #22
    Join Date
    Apr 2013
    Posts
    21
    deathshadow.

    That would be great. Since I don't seem to be getting emails when you respond, could you please email me (robert_kline@earthlink.net) when the stand-alone version is ready? I definitely have a use for it.

    BK

  8. #23
    Join Date
    Apr 2013
    Posts
    21
    Hey deathshadow,

    I hope you're still monitoring this thread. I'm using your econfirm script for another project and have run into a minor problem. When the user clicks on one of the "popup window" buttons, they're returned to the top of the invoking webpage. Turns out this was true in the membership form application, but the page was so small, that it was almost unnoticeable. The new project page is much larger and I want the user to be returned to the place on the page where they clicked the link.

    The econfirm script is invoked with:
    Code:
    Speaker: <a href="" onclick="getPayment();return false" onfocus="this.blur()">Click here</a> to learn about our special speaker.
    The javascript looks like this:
    Code:
    <script>
    function getPayment(){
        message = "Noted author, lecturer and button collector<p>Peggy Ann Osborne<p>Program will be presented via Skype from her home in Nova Scotia\n\n";
        confirm('Special Guest Presenter',message,getResults);
    }
    function getResults(results){return false}
    </script>
    I've tried a couple of things, including setting a tag, but it always goes to the top of the page (the page isn't reloaded, it just displays at the top).

    Any ideas?

    Thanks.
    BK

  9. #24
    Join Date
    May 2014
    Posts
    834
    The only thing that would cause that is the # in the anchor -- which a proper 'prevent' method would stop from propagating.

    Right after the 'confirm' function, you'd want to add something like this:
    Code:
    handlerAdd(confirmPaypal, 'click', function(e) {
    	confirm(
    		'Accept Paypal Surcharge?', 
    			/*
    				NOTE - this is one of the times JavaScript's lack of whitespace
    				neutral strings REALLY pisses me off
    			*/
    		'<p>There will be a ' + rate + '% surcharge for using PayPal.</p><p><span class="keepTogether"><b>Product Total:</b> $' + total.toFixed(2) + '</span> &bull; <span class="keepTogether"><b>Total Charge:</b> $' + (total * (rate + 100) / 100).toFixed(2) + '</b></span></p><p>Please click the Accept button to authorize this charge.<br />Otherwise click the Decline button.</p>',
    		alert
    	);
    	e.cancelBubble = true;
    	if (e.stopPropagation) e.stopPropagation();
    	if (e.preventDefault) e.preventDefault();
    	e.returnValue = false;
    }, true, true);
    though one thing I didn't point out, the href on that anchor should be changed to a verification URL -- so that scripting off the page still works. That's why for something like a FORM you'd attach the confirm to onsubmit, cancel the submit, then manually submit.

    Again, unwritten rule of JS - "If you can't make the page work without scripting FIRST, you likely have no business adding scripting to it!"
    Java is to JavaScript as Ham is to Hamburger.

  10. #25
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,342
    Simplest answer really is to do like the majority of sites who trade online do it, you show this information as part of your trading terms and have that amount already added in to the total and have the page with a continue to payment or cancel order.

    I understand that you are trying to pass on your losses that you make from a paypal trade, you should consider how detrimental this could be and record the number of purchases vs the failures at the checkout stage.

    Your alternative is to already build in to your pricing structure a percentage and have no need for any additional costs.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles