View Full Version : Trouble with functions

04-01-2009, 04:46 AM
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:

<script language="JavaScript">
function countit(){
var formcontent=document.wordcount.wordcount2.value
formcontent=formcontent.split(" ")
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)


$words = $_GET['words'];


And where I want the word count to populate:

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

Old Pedant
04-01-2009, 07:33 AM
Ummm...no...nothing to do with JavaScript.

On your checkout.php page, you coded:

<form name="grammarperfection" action="/confirmorder.php" method="post">

And when you use METHOD=POST, then your PHP code has to use

$words = $_POST['words'];

Go read up on the basics of PHP and working with <form> tags.

04-01-2009, 01:10 PM
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?