Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need javascript help

    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.
    Last edited by MitaDC; 08-25-2004 at 07:21 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


    Code:
    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.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ^ygpm

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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).
    Code:
    <button onclick="createEmailOrder()">place order</button>
    Sadiq.

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My partner and I built it but he did most of the JS so... thanks again

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bump ^

  • #9
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    (without smiley )
    Last edited by MitaDC; 09-01-2004 at 08:26 AM.

  • #10
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    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+intspk+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.

  • #11
    Regular Coder
    Join Date
    Aug 2004
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

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