Reply
Help to send js generated text into a textarea
Old 11-06-2009, 07:53 PM Help to send js generated text into a textarea
Junior Talker

Posts: 3
Trades: 0
Hello all

I have implemented a free javascript for client-side shopping cart into my site and works great. Only, at the very end of my work i realize there is no possible way to email the cart items to me! The reason is because the script is originally written to checkout to PayPal so i guess either i have to recode something, or i gotta use some trick.

You can see the code at http://lukulos.gr/simpleCart.js
This is only because the forum does not allow long threads.

What i have to do to output the cart's content is use a div or span, like:
<div class="simpleCart_items></div>
and the data gets generated on the page automatically.

But i would like this info to be written inside a textarea, so i can use it with my cgi's form mail script.

Anyone could help?
EUDIS is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-06-2009, 08:42 PM Re: Help to send js generated text into a textarea
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
It's just an idea, but as your cart is javascript based, obviously you can count on advanced javascript support when your customer use it.

So, why not design a page on your site that takes the cart content as a POST or GET parameter (and send it to you, or do whatever else) and let your cart send it via a simple AJAX request ?

Or, you could dynamically create a <form> element, and post it to your server (which is approximatively the same in this case)
Code:
<script type="text/javascript">
/*
Create a simple form with a textarea in it, and send it via POST to http://www.whatever.com/cartPost.php
*/
frm=document.createElement('form')
frm.action="http://www.whatever.com/cartPost.php"
frm.method="POST"
fld=document.createElement('textarea')
fld.appendChild(document.createTextNode(simpleCart.items))
frm.appendChild(fld)
frm.submit()
</script>
Maybe you could simply derive updateViewTotals() to have it return the HTML string, rather than directly inject it into the target html element.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-07-2009, 11:11 AM Re: Help to send js generated text into a textarea
Junior Talker

Posts: 3
Trades: 0
Well, i tried your second suggestion. Have put this script you posted to the end of the page, just before the </body> tag, to dynamically create the textarea. Of course i didn't yet include the last line, frm.submit(), to avoid sending anything before i test it. Thing is, i guess i should actually see a textarea with the contents of the cart being generated on the page, right? However nothing happens, not even the textarea appears :/

About your last suggestion, i don't know how to do that
EUDIS is offline
Reply With Quote
View Public Profile
 
Old 11-07-2009, 04:44 PM Re: Help to send js generated text into a textarea
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
of yourse it doesn't appears.
This script create DOM elements, but they need to be appended to the paeg to see it.
They only exists in memory right now.

Add this lien at the end of the script:
Code:
document.getElementsByTagName('html')[0].appendChild(frm);
This will add the form at the end of the first <html> element of the page
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-07-2009, 07:33 PM Re: Help to send js generated text into a textarea
Junior Talker

Posts: 3
Trades: 0
Hm... Ok, now it does create a textarea. But the text in it is "[object Object]" instead of the cart's contents
EUDIS is offline
Reply With Quote
View Public Profile
 
Old 11-08-2009, 10:10 AM Re: Help to send js generated text into a textarea
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
it's because of
Code:
fld.appendChild(document.createTextNode(simpleCart.items))
SimpleCart.items is an array of js objects.
You have to create a function that will give you back the description of those objects.
Like you do into the updateViewTotals() function.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Help to send js generated text into a textarea
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.12212 seconds with 13 queries