...

View Full Version : Need javascript help



MitaDC
08-25-2004, 07:19 PM
Alright this is my first post here so hopefully you guys will be nice lol... Anyways I have a company - PJComputes.net (not advertising it is just so u can see what i need).. Alright what I need help with is how to write a script that when somebody hits submit it emails us their computer configurations. Is this possible or is this too hard? Might need to use IE to view or page cuz some of the java scripts we use don't work in Firefox. Ok here is an example page

http://www.pjcomputers.net/pjx643000.shtml

as you can see at the bottom you can update the price but we would like to be able to recieve somebodies order in email form. Thank You if anybody can help.

sad69
08-25-2004, 07:58 PM
Firstly, that's a crazy looking computer case!

But to help you with your problem, I should mention something:

If you want the email to look just like this page, it is probably not going to be possible using Javascript (although I've heard of using innerHTML to get the contents of the page...). You'd be better of using a sever-side language, like PHP to generate this page.
You may want to re-evaluate the values you've given to these radio buttons to make this email look a bit nicer.

Not sure where you want to store the customer's information..
You may want to modify your price() function, so that you can make a call to it and include it's value in the the body of the email.





function createEmailOrder() {
var mailto = 'mailto:mailbox@pjcomputers.net?subject=Order&body=';
var body = '';

var inputs = document.getElementsByTagName('INPUT');
for(var i = 0; i < inputs.length; i++) {
var elem = inputs.item(i);
if(elem.getAttribute('type') == 'radio') {
if(elem.checked) {
body += elem.getAttribute('value')+"\n";
}
}
}

window.open(mailto+escape(body));
}


Hope that helps,
Sadiq.

MitaDC
08-25-2004, 08:36 PM
^ygpm

sad69
08-25-2004, 10:00 PM
Yes I got that... but I prefer to conduct my 'conversations' here rather than via PM.

Just a question, where did you get this webpage from? Did you build it or did someone else? If it was someone else, then that would be the person to talk to about this issue.

I just assumed you'd built it, so you knew something about Javascript as the scripting is slightly more advanced than a beginner's code.

But basically, you'd include a button someplace on that page and that button's onclick handler would call the function I posted above. You should place that function within some script tags someplace in your HTML file (either up top where you define all those variables, or down below where you've defined your price() function).


<button onclick="createEmailOrder()">place order</button>


Sadiq.

MitaDC
08-25-2004, 11:19 PM
My partner and I built it but he did most of the JS so... thanks again

sad69
08-25-2004, 11:52 PM
Well that's good that's he's your partner, then it should be easy to get in touch with him.

Explain to him what you want on the page and show him my function. He should be able to quickly understand what I'm talking about.

Good luck,
Sadiq.

HeadBand
08-30-2004, 07:12 AM
I am his partner, i know very little about java script...i just learned enough to make the page

is there another way this could be done by making the value of each variable be sent in the e-mail instead

HeadBand
09-01-2004, 06:42 AM
Bump ^

MitaDC
09-01-2004, 06:56 AM
thank you, is there a way to make it show the price also? Or anything else we would like to put in there?

Something like this


(Info)

Total Price: $100K :p

(without smiley :))

sad69
09-01-2004, 07:26 PM
Within that function I presented above, the body of the email is held within the body variable. Any text you add to the body variable will be printed in the email body.

I had to modify your price() function slightly to allow the price to be calculated and added to the email:


function createEmailOrder() {
var mailto = 'mailto:mailbox@pjcomputers.net?subject=Order&body=';
var body = '';

var inputs = document.getElementsByTagName('INPUT');
for(var i = 0; i < inputs.length; i++) {
var elem = inputs.item(i);
if(elem.getAttribute('type') == 'radio') {
if(elem.checked) {
body += elem.getAttribute('value')+"\n";
}
}
}

body += "\nTotal Price: $"+cost();

window.open(mailto+escape(body));
}

...

<SCRIPT type=text/javascript>
price();

function cost() {
return (1279+intcpu+intopt1+intopt2+inthdd+inthdd2+intram+intgc+intmod+intfdd+intkbm+intos+intmon+intprnt+i ntspk+intmic);
}

function price() {
document.getElementById('tot').innerHTML='<font color="black">Total Price:</font> $'+cost();
}
</SCRIPT>


So I've introduced a new function called cost() which will perform the calculation. I also replaced the line of code that was essentially the same as price() to merely call price(). So price() calls cost() to get the cost and displays it in the 'tot'.

createEmailOrder() will call cost() and display it in the body of the email.

Hope that helps,
Sadiq.

MitaDC
09-02-2004, 10:55 PM
alright thanks a lot, I just bought a book (JavaScript Bible 5th Edition) so I can really understand everything about this and so I can enhance our website. Thank you for your help

Where exactly do I add the info? Where is the body variable that I type stuff in, I am sorry lol I am trying though :P :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum