POST to a popup window

The most ‘fun’ thing about charity work is that price is no obstacle. When they describe something really supa-dupa to me, I tend to blink and say ‘Yes, well, that does sound like a good solution”, quietly acknowledging that they haven’t a clue just how much work they’re describing.

In the real world you, when hitting this situation, in parallel with preparing the quote for that Rolls-Royce version, I know I can go right ahead and prepare a cheaper, alternative vision which is more respectful of the budget they’ve actually got. When shown the first quote I know exactly what’s going to happen and like to be prepared.

But not so with a charity because the price difference between the Rolls-Royce and the Mini Minor is exactly zero. Presented with two solutions, one which will take me a month, and one which will take a minute, they inevitably opt for the one month solution because, frankly, it’s no skin off their nose. How to deal with this is the classic conundrum for anyone who voluntarily commits to ‘a worthy cause’.

Fortunately I’m not the principal on this occasion and can sympathetically deliver my little contribution to the poor bugger who is.

It’s some javascript to take the value of a donation and and popup the shopping cart of a partner site prefilled with the value and project id.

Sorry about the illegibility; wordpress wants to ‘help’ me. No doubt there’s another post in how to I choose to solve what is no doubt a common nuisance.

</p> <h3>Donation Amount</h3> <form> <input id=CAT_Custom_20066 type=text/></p> <input type=submit value=Donate onClick="spawnCNEC(CAT_Custom_20066.value, 'loan');"/> </form> <p><script type="text/javascript"><!-- // Spawn a new window to the cnecpi website and add a donation to the cart // donationValue: an integer corresponding to the dollar value of the donation // project: text string identifying the project to contribute to. Either 'dump' or 'loan'. // eg: // spawnCNEC(20, 'dump') // opens a cnec shopping cart with a $20 contribution to the Rubbish dump project function spawnCNEC(donationValue, project) {</p> <p> // cnec's cart and catalogue numbers for identifying the microloan or dump project const url = 'http://www.cnecpi.com.au/cart.html'; const loanID = '264'; const dumpID = '263';</p> <p> // default to the microloan item var itemID = loanID; if (project.match(/dump/)) // unless contributing to the dump :) itemID = dumpID;</p> <p> // create form to send to cnec var cForm = document.createElement('form'); cForm.target = 'cnecTarget'; cForm.method = 'POST'; cForm.action = url;</p> <p> // add the value of the donation (donationValue) var iPrice = document.createElement('input'); iPrice.type = 'hidden'; iPrice.name = 'price' + itemID; iPrice.value = donationValue; cForm.appendChild(iPrice);</p> <p> // add the cart id of the item var iHidden = document.createElement('input'); iHidden.type = 'hidden'; iHidden.name = 'addtocart'; iHidden.value = itemID; cForm.appendChild(iHidden);</p> <p> // attach and spawn submission in a new window document.getElementsByTagName("body")[0].appendChild(cForm); mywin=window.open(cForm.action,cForm.target,'scrollbars'); cForm.submit(); } --></script><br />

This entry was posted in geek and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>