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 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Trouble with functions

    Basically, I cannot get the functions from my javascript on this page:http://www.grammarperfection.com/cost.html to populate on my confirmation page: http://grammarperfection.com/confirmorder.php

    I have several javascript functions that relate to wordcount, cost (cost per word), and number of pages. I have all my javascript on one page, and will use the functions to populate data on two other pages.

    I am able to get the word count to populate on this page ok: http://grammarperfection.com/checkout.php, but cannot get it and the other functions to populate on this page: http://grammarperfection.com/confirmorder.php.

    I think the javascript is mostly right, I just need to know how to send it to this second page.

    See javascript:
    Code:

    Code:
    <script language="JavaScript">
          function countit(){
             var formcontent=document.wordcount.wordcount2.value
             formcontent=formcontent.split(" ")
             document.wordcount.wordcount3.value=formcontent.length
             document.quickcalculator.txtWordCount.value = formcontent.length;
          }
          function quickcalc(){
             var numWords = document.quickcalculator.txtWordCount.value;
             var costEstimate;
             var numPages = Math.ceil(numWords/300);
    
             // Standard Cost Estimate
             costEstimate = numPages*5.00;
             document.estimates.txtStandardEst.value = "$" + costEstimate.toFixed(2);
             // Expedite Cost Estimate
             costEstimate = numPages*7.50;
             document.estimates.txtExpediteEst.value = "$" + costEstimate.toFixed(2);
             // Overnight Cost Estimate
             costEstimate = numPages*9.00;
             document.estimates.txtOvernightEst.value = "$" + costEstimate.toFixed(2);
    
             // Display the estimate table.
             document.getElementById("tblEstimates").style.display = "block";
    
          }
          function goToCheckout(serviceOption){
             var numWords = document.quickcalculator.txtWordCount.value;
             var checkoutUrl = "/checkout.php?";         
     
             window.location.href = checkoutUrl + "serv=" + serviceOption + "&words=" + numWords;
          }
    Working on the second page I am having trouble with (http://grammarperfection.com/confirmorder.php), I started out with the word count feature and coded:
    (above the html)
    Code:

    Code:
    <?
    
    $words = $_GET['words']; 
    
    ?>
    And where I want the word count to populate:
    Code:

    Code:
    <input type="text" name="txtWordCount" size="20" maxlength="20" value="<? echo $words; ?>
    Any ideas on what I am doing wrong? I imagine I need to modify the javascript but am confused on what needs changed.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,720
    Thanks
    80
    Thanked 4,514 Times in 4,478 Posts
    Ummm...no...nothing to do with JavaScript.

    On your checkout.php page, you coded:
    Code:
    <form name="grammarperfection" action="/confirmorder.php" method="post">
    And when you use METHOD=POST, then your PHP code has to use
    Code:
    $words = $_POST['words'];
    Go read up on the basics of PHP and working with <form> tags.

  • #3
    New Coder
    Join Date
    Apr 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Exactly, I started using PHP, but is there a way to use basic HTML to reference the info from the prior page and post it on my confirmation page?


  •  

    Posting Permissions

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