Web Analytics Made Easy -
StatCounter Trouble with functions - CodingForum

Announcement

Collapse
No announcement yet.

Trouble with functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    Ummm...no...nothing to do with JavaScript.

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

    Comment


    • #3
      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?

      Comment

      Working...
      X