Avatar of catonthecouchproductions
catonthecouchproductions
Flag for United States of America asked on

Ajax varilables using php load to next page

When you go to this page: http://www.newspapersofamerica.com/new/?p=calc-spa-d

And play with the drop down, the values are being loaded via AJAX, here:

// USED FOR DISPLAY SPA
var currentIdD = -1;
var tIdD       = "";
function showPriceD() {
  var theForm = document.forms[1];
  var selD = theForm.state_id;
  var idD = theForm.state_id.value;
  if (currentIdD == idD) return; // not changed
  currentIdD=idD;
  var stateD = selD.options[selD.selectedIndex].text;
  var priceD = theForm.price.value;
  var sizeD = theForm.size.value;
  var paper_nameD = theForm.paper_name.value;
  var locD = 'spaPricesD.php?state_id='+idD+'&price='+priceD+'&size='+sizeD+'&paper_name='+paper_nameD;
  document.getElementById('GroupPrice').innerHTML= 'Loading prices for '+stateD+'...';
  window.if1.location=locD;
}

The link I sent above, after form is filled out and on submit it goes to the confirm page, since my other form variables that ARENT using ajax and loaded via mysql in to PHP variables.

I need to find a way to get:

state_jd
price
size
paper_name

To the PHP page, another example not using AJAX is here:

http://www.newspapersofamerica.com/new/index.php?p=calc-d&id=1

Same idea.

Any ideas?

Thanks,

Ryan
PHPJavaScript

Avatar of undefined
Last Comment
catonthecouchproductions

8/22/2022 - Mon
Steve Bink

To clarify, you are using a form control to trigger an AJAX script.  The script queries the database for the price and other info, and returns to HTML elements.  You want to be able to pass this information to the form handler once the form is submitted.  Is that correct?

When your AJAX script returns the info, put it into hidden form fields as well as your display element.  When the form is submitted, your handler will be able to see the data in $_POST just like the 'normal' fields.
catonthecouchproductions

ASKER
Yeah! That is what I am confused about though, is how to get those fields loaded via ajax in to a hidden form.

Ryan
mettletechnlogies

you have to put hidden feild in 'spaPricesD.php" in this page and also in current page now before submit the current form u have to asign the value of hidden ajax form feild to current form feild. it will work fine.
looking for code snipt write to me.
http://mettlewebsolutions.blogspot.com/ 
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
catonthecouchproductions

ASKER
Alrighty, I think I get what you are saying, so below is my code for that page, spaPricesD.php.

Do I put my form say the bottom with the names of the field being that ones I want to send over.
<script>
var groupText="";
<?php
include_once ("config.php");
 
if($_REQUEST["state_id"]){
  $state_id     = htmlspecialchars(stripslashes($_REQUEST["state_id"]));
  $sql    = "SELECT displayPrice,displaySize,state_id FROM spa_states WHERE state_id=$state_id";
  $query  = mysql_query($sql) or die(mysql_error());
  while($row = mysql_fetch_array($query)) {
    if ($row["displayPrice"]!="") {
      print "\ngroupText='<b>$".$row["displayPrice"]." for ".$row["displaySize"]." column inche(s).</b>';";  
      print "\nparent.document.getElementById('GroupPrice').innerHTML=groupText;";
 
    }
    else {
      print "\ngroupText='No price/data for this ID.'";
    }    
  }
}
else{
  print "\ngroupText='Must have a valid ID to continue.'";
}
?>
 
</script>

Open in new window

ASKER CERTIFIED SOLUTION
mettletechnlogies

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
catonthecouchproductions

ASKER
Thank you! Now when i navigate to this page to test it: http://127.0.0.1/clients/newspapersofamerica/?p=calc-spa-d

No matter what state I pick it does:

Loading prices for Georgia...

And doesnt print out values. Below is my spaPricesD.php
<script>
var groupText="";
<?php
include_once ("config.php");
 
if($_REQUEST["state_id"]){
  $state_id     = htmlspecialchars(stripslashes($_REQUEST["state_id"]));
  $sql    = "SELECT displayPrice,displaySize,state_id FROM spa_states WHERE state_id=$state_id";
  $query  = mysql_query($sql) or die(mysql_error());
  while($row = mysql_fetch_array($query)) {
    if ($row["displayPrice"]!="") {
      print "\ngroupText='<b>$".$row["displayPrice"]." for ".$row["displaySize"]." column inche(s).</b>';";  
      print "\nparent.document.getElementById('GroupPrice').innerHTML=groupText;";
 
    }
    else {
      print "\ngroupText='No price/data for this ID.'";
    }    
  }
}
else{
  print "\ngroupText='Must have a valid ID to continue.'";
}
print " <input type='hidden'  id='state_id' value='".$state_id."' />";
 
?>

Open in new window

catonthecouchproductions

ASKER
Here is my calc-spa-d.php file, where the form is:


<?php
 
  if(isset($_POST['submit'])) {
 
     $fields = array("fn"=>"First Name", "ln"=>"Last Name", "company"=>"Company Name", "email"=>"E-mail","phone"=>"Phone","date"=>"Starting Date","comments"=>"Comments");
     $error_message = "<b>Please complete the following fields:</b> <br>";
     $error         = 0;
 
     foreach($fields  as $key=>$value){
          if(!isset($_POST[$key]) || empty($_POST[$key])){
               $error_message .= $value."<br>"; 
               $error = 1;
          }
     }
 
     $name = $_FILES['imagefile']['name'];
     $type = strtolower($_FILES['imagefile']['type']);
 
     if ( strlen($name) > 0 ) {
          if ( $type != "image/gif" && $type != "image/jpeg" && $type != "image/png" && $type != "image/jpg" ) {
               $error = 1;
               $error_message .= "<p>The file type ($type) is invalid - please use jpg, png or gif</p>";
          }
     }
     move_uploaded_file ($_FILES['imagefile']['tmp_name'], "images/imageUploads/".$name );
 
if(empty($error)){
$weeks    = $_REQUEST["weeks"];
$fn       = $_REQUEST["fn"];
$ln       = $_REQUEST["ln"];
$company  = $_REQUEST["company"];
$email    = $_REQUEST["email"];
$phone    = $_REQUEST["phone"];
$date     = $_REQUEST["date"];
$comments = $_REQUEST["comments"];
$price    = $_REQUEST["price"];
$size     = $_REQUEST["size"];
$paper_name = $_REQUEST["paper_name"];   
   
$params  = "weeks=".urlencode($weeks)."&";
$params .= "fn=".urlencode($fn)."&";
$params .= "ln=".urlencode($ln)."&";
$params .= "company=".urlencode($company)."&";
$params .= "email=".urlencode($email)."&";
$params .= "phone=".urlencode($phone)."&";
$params .= "date=".urlencode($date)."&";
$params .= "comments=".urlencode($comments)."&";
$params .= "price=".urlencode($price)."&";
$params .= "size=".urlencode($size)."&";
$params .= "paper_name=".urlencode($paper_name)."&";
$params .= "uploadedFile=".urlencode($name);
$params .= "&p=confirm-d";
$params .= "&id=". intval($_REQUEST['id']);
$loc     = "http://{$_SERVER['HTTP_HOST']}/". dirname($_SERVER['PHP_SELF']). "/index.php?$params";
 	echo $loc. "<br />\n";
 	die(1);
    header("Location: $loc");
        exit;
     }
     else
          print $error_message;
  }
  
?>
  
	<h2>Place Ad for SPA</h2>
	<span id="GroupPrice"></span><br />
	<span id="WordPrice"></span><br />
	<form name="calculate-spa-d" action="index.php" method="post" class="niceform" enctype="multipart/form-data">
	<label for="state_id">Choose state:</label><br />  
	<select name="state_id" id="state_id" onChange="this.form.submit()" >
 
<?php
 
   $ln        = htmlspecialchars( stripslashes( $_REQUEST['ln'] ), ENT_QUOTES );
   $fn        = htmlspecialchars( stripslashes( $_REQUEST['fn'] ), ENT_QUOTES );
   $company   = htmlspecialchars( stripslashes( $_REQUEST['company'] ), ENT_QUOTES );
   $email     = htmlspecialchars( stripslashes( $_REQUEST['email'] ), ENT_QUOTES );
   $phone     = htmlspecialchars( stripslashes( $_REQUEST['phone'] ), ENT_QUOTES );
   $date      = htmlspecialchars( stripslashes( $_REQUEST['date'] ), ENT_QUOTES );
   $comments  = htmlspecialchars( stripslashes( $_REQUEST['comments'] ), ENT_QUOTES );
   $imagefile = htmlspecialchars( stripslashes( $_REQUEST['imagefile'] ), ENT_QUOTES );
   $state     = "SELECT state_id, state_name FROM spa_states WHERE state_id<>2 AND state_id<>9 AND state_id<>11 AND state_id<>23 AND state_id<>22 AND state_id<>25 AND state_id<>26 ORDER BY state_id ASC";
   $result    = mysql_query($state) or die(mysql_error());
   while ($row1 = mysql_fetch_array($result)){
	   print '<option value="'.$row1["state_id"].'">'.$row1["state_name"].'</option>'."\n";
   }
   print '</select><br />';
?>
            <label for="weeks">Weeks to run ad:</label><br />
            <select name="weeks" id="weeks">
            <option value="1">1 week</option>
            <option value="2">2 weeks</option>
            <option value="3">3 weeks</option>
            <option value="4">4 weeks</option>
            </select><br />
            
            <label for="fn">First Name:</label><br />
            <input type="text" name="fn" id="fn" size="20" value="<?php echo $fn; ?>" /><br />
            <label for="ln">Last Name:</label><br />
            <input type="text" name="ln" id="ln" size="20" value="<?php echo $ln; ?>" /><br />
            <label for="company">Company Name:</label><br />
            <input type="text" name="company" id="company" size="20" value="<?php echo $company; ?>" /><br />
            <label for="email">E-mail:</label><br />
            <input type="text" name="email" id="email" size="20" value="<?php echo $email; ?>" /><br />
            <label for="phone">Phone:</label><br />
            <input type="text" name="phone" id="phone" size="20" value="<?php echo $phone; ?>" /><br />
            <label for="date">Starting Date:</label><br />
            <input type="text" name="date" id="date" size="20" title="Click to select date" value="<?php echo $date; ?>" /><br />
            <label for="comments">Comments:</label><br />
            <textarea name="comments" id="comments" rows="5" cols="20"><?php echo $comments; ?></textarea><br />
            <label for="comments">Display Ad:</label><br />
            <input type="file" name="imagefile" /><br /><br />
            <input name="p" type="hidden" value="calc-spa-d" />
            <input type="hidden" name="price" value="<?php echo $price; ?>">
            <input type="hidden" name="size" value="<?php echo $size; ?>">
            <input type="hidden" name="paper_name" value="<?php echo $state; ?>">
            <input name="id" type="hidden" value="<?php echo intval($_REQUEST['id']); ?>" />
            
            
            <input type='hidden' id='state_id_submit' value='' />
            <script type='javascript' >
            function setvalue(){
               document.getElementById('state_id_submit').value=document.getElementById('state_id').value;
            }
            </script>
            <input type="submit" name="Submit" value="Calculate!" />
 
</form>
<iframe name="if1" src="about:blank" width="1" height="1"></iframe>
<script>
	 tId1 = setInterval('showPriceD()',200);
</script>

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mettletechnlogies

hi i just gave u an example of getting state_id . i don know whether its required or not so plz do the hidden field of which u want in ajax call page and same in ur main form u ll get the data post.
 thnx
kailash
kailashju78@gmail.com
http://mettlewebsolution.blogspot.com
catonthecouchproductions

ASKER
So I have:

<input type="hidden" name="state_id" value="">          
            <input type="hidden" name="price" value="">
            <input type="hidden" name="size" value="">
            <input type="hidden" name="paper_name" value="">
            <script type='javascript' >
            function setvalue(){
               document.getElementById('state_id_submit').value=document.getElementById('state_id').value;
            }
            </script>

For this line:
               document.getElementById('state_id_submit').value=document.getElementById('state_id').value;

Do I copy/paste that for my other form fields I added in?
catonthecouchproductions

ASKER
Like so:
            <input type="hidden" name="state_id" id="state_id" value="">           
            <input type="hidden" name="price" id="price" value="">
            <input type="hidden" name="size" id="size" value="">
            <input type="hidden" name="paper_name" id="paper_name" value="">
            <script type='javascript' >
            function setvalue(){
               document.getElementById('state_id').value=document.getElementById('state_id').value;
               document.getElementById('price').value=document.getElementById('price').value;
               document.getElementById('size').value=document.getElementById('size').value;
               document.getElementById('paper_name').value=document.getElementById('paper_name').value;
            }
            </script>

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
catonthecouchproductions

ASKER
With this code below I get:

selD.selectedIndex is undefined
http://127.0.0.1/clients/newspapersofamerica/?p=calc-spa-d
Line 59

Line 59 is:
  var stateD = selD.options[selD.selectedIndex].text;

Of this section of code below:

// USED FOR DISPLAY SPA
var currentIdD = -1;
var tIdD       = "";
function showPriceD() {
  var theForm = document.forms[1];
  var selD = theForm.state_id;
  var idD = theForm.state_id.value;
  if (currentIdD == idD) return; // not changed
  currentIdD=idD;
  var stateD = selD.options[selD.selectedIndex].text;
  var priceD = theForm.price.value;
  var sizeD = theForm.size.value;
  var paper_nameD = theForm.paper_name.value;
  var locD = 'spaPricesD.php?state_id='+idD+'&price='+priceD+'&size='+sizeD+'&paper_name='+paper_nameD;
  document.getElementById('GroupPrice').innerHTML= 'Loading prices for '+stateD+'...';
  window.if1.location=locD;
}

Not sure why it is doing that, I didn't change my select drop-down, I only touched the hidden fields at the bottom of my form. What can I do to fix that?

Thanks for  your help, appreciate it.

Ryan
<?php
 
  if(isset($_POST['submit'])) {
 
     $fields = array("fn"=>"First Name", "ln"=>"Last Name", "company"=>"Company Name", "email"=>"E-mail","phone"=>"Phone","date"=>"Starting Date","comments"=>"Comments");
     $error_message = "<b>Please complete the following fields:</b> <br>";
     $error         = 0;
 
     foreach($fields  as $key=>$value){
          if(!isset($_POST[$key]) || empty($_POST[$key])){
               $error_message .= $value."<br>"; 
               $error = 1;
          }
     }
 
     $name = $_FILES['imagefile']['name'];
     $type = strtolower($_FILES['imagefile']['type']);
 
     if ( strlen($name) > 0 ) {
          if ( $type != "image/gif" && $type != "image/jpeg" && $type != "image/png" && $type != "image/jpg" ) {
               $error = 1;
               $error_message .= "<p>The file type ($type) is invalid - please use jpg, png or gif</p>";
          }
     }
     move_uploaded_file ($_FILES['imagefile']['tmp_name'], "images/imageUploads/".$name );
 
if(empty($error)){
$weeks    = $_REQUEST["weeks"];
$fn       = $_REQUEST["fn"];
$ln       = $_REQUEST["ln"];
$company  = $_REQUEST["company"];
$email    = $_REQUEST["email"];
$phone    = $_REQUEST["phone"];
$date     = $_REQUEST["date"];
$comments = $_REQUEST["comments"];
$price    = $_REQUEST["price"];
$size     = $_REQUEST["size"];
$paper_name = $_REQUEST["paper_name"];   
   
$params  = "weeks=".urlencode($weeks)."&";
$params .= "fn=".urlencode($fn)."&";
$params .= "ln=".urlencode($ln)."&";
$params .= "company=".urlencode($company)."&";
$params .= "email=".urlencode($email)."&";
$params .= "phone=".urlencode($phone)."&";
$params .= "date=".urlencode($date)."&";
$params .= "comments=".urlencode($comments)."&";
$params .= "price=".urlencode($price)."&";
$params .= "size=".urlencode($size)."&";
$params .= "paper_name=".urlencode($paper_name)."&";
$params .= "uploadedFile=".urlencode($name);
$params .= "&p=confirm-d";
$params .= "&id=". intval($_REQUEST['id']);
$loc     = "http://{$_SERVER['HTTP_HOST']}/". dirname($_SERVER['PHP_SELF']). "/index.php?$params";
 	echo $loc. "<br />\n";
 	die(1);
    header("Location: $loc");
        exit;
     }
     else
          print $error_message;
  }
  
?>
  
	<h2>Place Ad for SPA</h2>
	<span id="GroupPrice"></span><br />
	<span id="WordPrice"></span><br />
	<form name="calculate-spa-d" action="index.php" method="post" class="niceform" enctype="multipart/form-data">
	<label for="state_id">Choose state:</label><br />  
	<select name="state_id" id="state_id" onChange="this.form.submit()" >
 
<?php
 
   $ln        = htmlspecialchars( stripslashes( $_REQUEST['ln'] ), ENT_QUOTES );
   $fn        = htmlspecialchars( stripslashes( $_REQUEST['fn'] ), ENT_QUOTES );
   $company   = htmlspecialchars( stripslashes( $_REQUEST['company'] ), ENT_QUOTES );
   $email     = htmlspecialchars( stripslashes( $_REQUEST['email'] ), ENT_QUOTES );
   $phone     = htmlspecialchars( stripslashes( $_REQUEST['phone'] ), ENT_QUOTES );
   $date      = htmlspecialchars( stripslashes( $_REQUEST['date'] ), ENT_QUOTES );
   $comments  = htmlspecialchars( stripslashes( $_REQUEST['comments'] ), ENT_QUOTES );
   $imagefile = htmlspecialchars( stripslashes( $_REQUEST['imagefile'] ), ENT_QUOTES );
   $state     = "SELECT state_id, state_name FROM spa_states WHERE state_id<>2 AND state_id<>9 AND state_id<>11 AND state_id<>23 AND state_id<>22 AND state_id<>25 AND state_id<>26 ORDER BY state_id ASC";
   $result    = mysql_query($state) or die(mysql_error());
   while ($row1 = mysql_fetch_array($result)){
	   print '<option value="'.$row1["state_id"].'">'.$row1["state_name"].'</option>'."\n";
   }
   print '</select><br />';
?>
            <label for="weeks">Weeks to run ad:</label><br />
            <select name="weeks" id="weeks">
            <option value="1">1 week</option>
            <option value="2">2 weeks</option>
            <option value="3">3 weeks</option>
            <option value="4">4 weeks</option>
            </select><br />
            
            <label for="fn">First Name:</label><br />
            <input type="text" name="fn" id="fn" size="20" value="<?php echo $fn; ?>" /><br />
            <label for="ln">Last Name:</label><br />
            <input type="text" name="ln" id="ln" size="20" value="<?php echo $ln; ?>" /><br />
            <label for="company">Company Name:</label><br />
            <input type="text" name="company" id="company" size="20" value="<?php echo $company; ?>" /><br />
            <label for="email">E-mail:</label><br />
            <input type="text" name="email" id="email" size="20" value="<?php echo $email; ?>" /><br />
            <label for="phone">Phone:</label><br />
            <input type="text" name="phone" id="phone" size="20" value="<?php echo $phone; ?>" /><br />
            <label for="date">Starting Date:</label><br />
            <input type="text" name="date" id="date" size="20" title="Click to select date" value="<?php echo $date; ?>" /><br />
            <label for="comments">Comments:</label><br />
            <textarea name="comments" id="comments" rows="5" cols="20"><?php echo $comments; ?></textarea><br />
            <label for="comments">Display Ad:</label><br />
            <input type="file" name="imagefile" /><br /><br />
            <input name="p" type="hidden" value="calc-spa-d" />
            <input name="id" type="hidden" value="<?php echo intval($_REQUEST['id']); ?>" />
            <input type="hidden" name="state_id" id="state_id" value="">           
            <input type="hidden" name="price" id="price" value="">
            <input type="hidden" name="size" id="size" value="">
            <input type="hidden" name="paper_name" id="paper_name" value="">
            <script type='javascript' >
            function setvalue(){
               document.getElementById('state_id').value=document.getElementById('state_id').value;
               document.getElementById('price').value=document.getElementById('price').value;
               document.getElementById('size').value=document.getElementById('size').value;
               document.getElementById('paper_name').value=document.getElementById('paper_name').value;
            }
            </script>
            <input type="submit" name="Submit" value="Calculate!" />
 
</form>
<iframe name="if1" src="about:blank" width="1" height="1"></iframe>
<script>
	 tId1 = setInterval('showPriceD()',200);
</script>

Open in new window

mettletechnlogies

why did u got last error  i don know but for ajax
you have to assign four hidden feild in ur spapriced.php
state_id_ajax,price_ajax,size_ajax,paper_name_ajax
put the value when call the ajax
now in ur main page create four hidden feild
state_id_submit,price_submit,size_submit,paper_name_submit
now u call javacsript when u submit the value
document.getElementById('state_id_submit').value=document.getElementById('state_id_ajax').value;
               document.getElementById('price_submit').value=document.getElementById('price_ajax').value;
               document.getElementById('size_submit').value=document.getElementById('size_ajax').value;
               document.getElementById('paper_name_submit').value=document.getElementById('paper_name_ajax').value;
           
 kailash
kailashju78@gmail.com
http://mettlewebsolution.blogspot.com/
catonthecouchproductions

ASKER
So my spaPricesD.php:

<script>
var groupText="";
<?php
include_once ("config.php");
 
if($_REQUEST["state_id"]){
  $state_id     = htmlspecialchars(stripslashes($_REQUEST["state_id"]));
  $sql    = "SELECT displayPrice,displaySize,state_id FROM spa_states WHERE state_id=$state_id";
  $query  = mysql_query($sql) or die(mysql_error());
  while($row = mysql_fetch_array($query)) {
    if ($row["displayPrice"]!="") {
      print "\ngroupText='<b>$".$row["displayPrice"]." for ".$row["displaySize"]." column inche(s).</b>';";  
      print "\nparent.document.getElementById('GroupPrice').innerHTML=groupText;";
 
    }
    else {
      print "\ngroupText='No price/data for this ID.'";
    }    
  }
}
else{
  print "\ngroupText='Must have a valid ID to continue.'";
}
print " <input type='hidden'  id='state_id_ajax' value='".$state_id_ajax."' />";
print " <input type='hidden'  id='size_ajax' value='".$size_ajax."' />";
print " <input type='hidden'  id='price_ajax' value='".$price_ajax."' />";
print " <input type='hidden'  id='paper_name_ajax' value='".$paper_name_ajax."' />";

?>

my calc-spa-d.php:

<?php
 
  if(isset($_POST['submit'])) {

     $fields = array("fn"=>"First Name", "ln"=>"Last Name", "company"=>"Company Name", "email"=>"E-mail","phone"=>"Phone","date"=>"Starting Date","comments"=>"Comments");
     $error_message = "<b>Please complete the following fields:</b> <br>";
     $error         = 0;
 
     foreach($fields  as $key=>$value){
          if(!isset($_POST[$key]) || empty($_POST[$key])){
               $error_message .= $value."<br>";
               $error = 1;
          }
     }

     $name = $_FILES['imagefile']['name'];
     $type = strtolower($_FILES['imagefile']['type']);
 
     if ( strlen($name) > 0 ) {
          if ( $type != "image/gif" && $type != "image/jpeg" && $type != "image/png" && $type != "image/jpg" ) {
               $error = 1;
               $error_message .= "<p>The file type ($type) is invalid - please use jpg, png or gif</p>";
          }
     }
     move_uploaded_file ($_FILES['imagefile']['tmp_name'], "images/imageUploads/".$name );

if(empty($error)){
$weeks    = $_REQUEST["weeks"];
$fn       = $_REQUEST["fn"];
$ln       = $_REQUEST["ln"];
$company  = $_REQUEST["company"];
$email    = $_REQUEST["email"];
$phone    = $_REQUEST["phone"];
$date     = $_REQUEST["date"];
$comments = $_REQUEST["comments"];
$price    = $_REQUEST["price"];
$size     = $_REQUEST["size"];
$paper_name = $_REQUEST["paper_name"];  
   
$params  = "weeks=".urlencode($weeks)."&";
$params .= "fn=".urlencode($fn)."&";
$params .= "ln=".urlencode($ln)."&";
$params .= "company=".urlencode($company)."&";
$params .= "email=".urlencode($email)."&";
$params .= "phone=".urlencode($phone)."&";
$params .= "date=".urlencode($date)."&";
$params .= "comments=".urlencode($comments)."&";
$params .= "price=".urlencode($price)."&";
$params .= "size=".urlencode($size)."&";
$params .= "paper_name=".urlencode($paper_name)."&";
$params .= "uploadedFile=".urlencode($name);
$params .= "&p=confirm-d";
$params .= "&id=". intval($_REQUEST['id']);
$loc     = "http://{$_SERVER['HTTP_HOST']}/". dirname($_SERVER['PHP_SELF']). "/index.php?$params";
       echo $loc. "<br />\n";
       die(1);
    header("Location: $loc");
        exit;
     }
     else
          print $error_message;
  }
 
?>
 
      <h2>Place Ad for SPA</h2>
      <span id="GroupPrice"></span><br />
      <span id="WordPrice"></span><br />
      <form name="calculate-spa-d" action="index.php" method="post" class="niceform" enctype="multipart/form-data">
      <label for="state_id">Choose state:</label><br />  
      <select name="state_id" id="state_id" onChange="this.form.submit()" >

<?php

   $ln        = htmlspecialchars( stripslashes( $_REQUEST['ln'] ), ENT_QUOTES );
   $fn        = htmlspecialchars( stripslashes( $_REQUEST['fn'] ), ENT_QUOTES );
   $company   = htmlspecialchars( stripslashes( $_REQUEST['company'] ), ENT_QUOTES );
   $email     = htmlspecialchars( stripslashes( $_REQUEST['email'] ), ENT_QUOTES );
   $phone     = htmlspecialchars( stripslashes( $_REQUEST['phone'] ), ENT_QUOTES );
   $date      = htmlspecialchars( stripslashes( $_REQUEST['date'] ), ENT_QUOTES );
   $comments  = htmlspecialchars( stripslashes( $_REQUEST['comments'] ), ENT_QUOTES );
   $imagefile = htmlspecialchars( stripslashes( $_REQUEST['imagefile'] ), ENT_QUOTES );
   $state     = "SELECT state_id, state_name FROM spa_states WHERE state_id<>2 AND state_id<>9 AND state_id<>11 AND state_id<>23 AND state_id<>22 AND state_id<>25 AND state_id<>26 ORDER BY state_id ASC";
   $result    = mysql_query($state) or die(mysql_error());
   while ($row1 = mysql_fetch_array($result)){
         print '<option value="'.$row1["state_id"].'">'.$row1["state_name"].'</option>'."\n";
   }
   print '</select><br />';
?>
            <label for="weeks">Weeks to run ad:</label><br />
            <select name="weeks" id="weeks">
            <option value="1">1 week</option>
            <option value="2">2 weeks</option>
            <option value="3">3 weeks</option>
            <option value="4">4 weeks</option>
            </select><br />
           
            <label for="fn">First Name:</label><br />
            <input type="text" name="fn" id="fn" size="20" value="<?php echo $fn; ?>" /><br />
            <label for="ln">Last Name:</label><br />
            <input type="text" name="ln" id="ln" size="20" value="<?php echo $ln; ?>" /><br />
            <label for="company">Company Name:</label><br />
            <input type="text" name="company" id="company" size="20" value="<?php echo $company; ?>" /><br />
            <label for="email">E-mail:</label><br />
            <input type="text" name="email" id="email" size="20" value="<?php echo $email; ?>" /><br />
            <label for="phone">Phone:</label><br />
            <input type="text" name="phone" id="phone" size="20" value="<?php echo $phone; ?>" /><br />
            <label for="date">Starting Date:</label><br />
            <input type="text" name="date" id="date" size="20" title="Click to select date" value="<?php echo $date; ?>" /><br />
            <label for="comments">Comments:</label><br />
            <textarea name="comments" id="comments" rows="5" cols="20"><?php echo $comments; ?></textarea><br />
            <label for="comments">Display Ad:</label><br />
            <input type="file" name="imagefile" /><br /><br />
            <input name="p" type="hidden" value="calc-spa-d" />
            <input name="id" type="hidden" value="<?php echo intval($_REQUEST['id']); ?>" />
            <input type="hidden" name="state_id_submit" id="state_id_submit" value=""/>          
            <input type="hidden" name="price_submit" id="price_submit" value=""/>
            <input type="hidden" name="size_submit" id="size_submit" value=""/>
            <input type="hidden" name="paper_name_submit" id="paper_name_submit" value=""/>
            <script type='javascript' >
            function setvalue(){
               document.getElementById('state_id_submit').value=document.getElementById('state_id_ajax').value;
               document.getElementById('price_submit').value=document.getElementById('price_ajax').value;
               document.getElementById('size_submit').value=document.getElementById('size_ajax').value;
               document.getElementById('paper_name_submit').value=document.getElementById('paper_name_ajax').value;
            }
            </script>
            <input type="submit" name="Submit" value="Calculate!" />

</form>
<iframe name="if1" src="about:blank" width="1" height="1"></iframe>
<script>
       tId1 = setInterval('showPriceD()',200);
</script>


Does that look right?

Thank you for your help! I have never done passing ajax to php variables to send to a page, so I am lost, haha.

Ryan

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
catonthecouchproductions

ASKER
I fixed that error, my new code for spaPricesD.php is below:
<script>
var groupText="";
<?php
include_once ("config.php");
 
if($_REQUEST["state_id"]){
    
  $state_id     = htmlspecialchars(stripslashes($_REQUEST["state_id"]));
  $sql          = "SELECT displayPrice,displaySize,state_id FROM spa_states WHERE state_id=$state_id";
  $query        = mysql_query($sql) or die(mysql_error());
  
  while($row = mysql_fetch_array($query)) {
    if ($row["displayPrice"]!="") {
      print "\ngroupText='<b>$".$row["displayPrice"]." for ".$row["displaySize"]." column inche(s).</b>';\n";  
      print "\nparent.document.getElementById('GroupPrice').innerHTML=groupText;\n";
    }else{
      print "\ngroupText='No price/data for this ID.'";
    }    
    }
}
else{
  print "\ngroupText='Must have a valid ID to continue.'";
}
?>
</script>
<?
print "\n<input type='hidden'  id='state_id_ajax' value='".$state_id_ajax."' />";
print "\n<input type='hidden'  id='size_ajax' value='".$size_ajax."' />";
print "\n<input type='hidden'  id='price_ajax' value='".$price_ajax."' />";
print "\n<input type='hidden'  id='paper_name_ajax' value='".$paper_name_ajax."' />\n";
?>

Open in new window

catonthecouchproductions

ASKER
My calc-spa-d.php is below.
<?php
 
  if(isset($_POST['submit'])) {
 
     $fields = array("fn"=>"First Name", "ln"=>"Last Name", "company"=>"Company Name", "email"=>"E-mail","phone"=>"Phone","date"=>"Starting Date","comments"=>"Comments");
     $error_message = "<b>Please complete the following fields:</b> <br>";
     $error         = 0;
 
     foreach($fields  as $key=>$value){
          if(!isset($_POST[$key]) || empty($_POST[$key])){
               $error_message .= $value."<br>"; 
               $error = 1;
          }
     }
 
     $name = $_FILES['imagefile']['name'];
     $type = strtolower($_FILES['imagefile']['type']);
 
     if ( strlen($name) > 0 ) {
          if ( $type != "image/gif" && $type != "image/jpeg" && $type != "image/png" && $type != "image/jpg" ) {
               $error = 1;
               $error_message .= "<p>The file type ($type) is invalid - please use jpg, png or gif</p>";
          }
     }
     move_uploaded_file ($_FILES['imagefile']['tmp_name'], "images/imageUploads/".$name );
 
if(empty($error)){
$weeks    = $_REQUEST["weeks"];
$fn       = $_REQUEST["fn"];
$ln       = $_REQUEST["ln"];
$company  = $_REQUEST["company"];
$email    = $_REQUEST["email"];
$phone    = $_REQUEST["phone"];
$date     = $_REQUEST["date"];
$comments = $_REQUEST["comments"];
$price    = $_REQUEST["price"];
$size     = $_REQUEST["size"];
$paper_name = $_REQUEST["paper_name"];   
   
$params  = "weeks=".urlencode($weeks)."&";
$params .= "fn=".urlencode($fn)."&";
$params .= "ln=".urlencode($ln)."&";
$params .= "company=".urlencode($company)."&";
$params .= "email=".urlencode($email)."&";
$params .= "phone=".urlencode($phone)."&";
$params .= "date=".urlencode($date)."&";
$params .= "comments=".urlencode($comments)."&";
$params .= "price=".urlencode($price)."&";
$params .= "size=".urlencode($size)."&";
$params .= "paper_name=".urlencode($paper_name)."&";
$params .= "uploadedFile=".urlencode($name);
$params .= "&p=confirm-d";
$params .= "&id=". intval($_REQUEST['id']);
$loc     = "http://{$_SERVER['HTTP_HOST']}/". dirname($_SERVER['PHP_SELF']). "/index.php?$params";
 	echo $loc. "<br />\n";
 	die(1);
    header("Location: $loc");
        exit;
     }
     else
          print $error_message;
  }
  
?>
  
	<h2>Place Ad for SPA</h2>
	<span id="GroupPrice"></span><br />
	<form name="calculate-spa-d" action="index.php" name="theForm" method="post" class="niceform" enctype="multipart/form-data">
	<label for="state_id">Choose state:</label><br />  
	<select name="state_id" id="state_id" onChange="this.form.submit()" >
 
<?php
 
   $ln        = htmlspecialchars( stripslashes( $_REQUEST['ln'] ), ENT_QUOTES );
   $fn        = htmlspecialchars( stripslashes( $_REQUEST['fn'] ), ENT_QUOTES );
   $company   = htmlspecialchars( stripslashes( $_REQUEST['company'] ), ENT_QUOTES );
   $email     = htmlspecialchars( stripslashes( $_REQUEST['email'] ), ENT_QUOTES );
   $phone     = htmlspecialchars( stripslashes( $_REQUEST['phone'] ), ENT_QUOTES );
   $date      = htmlspecialchars( stripslashes( $_REQUEST['date'] ), ENT_QUOTES );
   $comments  = htmlspecialchars( stripslashes( $_REQUEST['comments'] ), ENT_QUOTES );
   $imagefile = htmlspecialchars( stripslashes( $_REQUEST['imagefile'] ), ENT_QUOTES );
   $state     = "SELECT state_id, state_name FROM spa_states WHERE state_id<>2 AND state_id<>9 AND state_id<>11 AND state_id<>23 AND state_id<>22 AND state_id<>25 AND state_id<>26 ORDER BY state_id ASC";
   $result    = mysql_query($state) or die(mysql_error());
   while ($row1 = mysql_fetch_array($result)){
	   print '<option value="'.$row1["state_id"].'">'.$row1["state_name"].'</option>'."\n";
   }
   print '</select><br />';
?>
            <label for="weeks">Weeks to run ad:</label><br />
            <select name="weeks" id="weeks">
            <option value="1">1 week</option>
            <option value="2">2 weeks</option>
            <option value="3">3 weeks</option>
            <option value="4">4 weeks</option>
            </select><br />
            
            <label for="fn">First Name:</label><br />
            <input type="text" name="fn" id="fn" size="20" value="<?php echo $fn; ?>" /><br />
            <label for="ln">Last Name:</label><br />
            <input type="text" name="ln" id="ln" size="20" value="<?php echo $ln; ?>" /><br />
            <label for="company">Company Name:</label><br />
            <input type="text" name="company" id="company" size="20" value="<?php echo $company; ?>" /><br />
            <label for="email">E-mail:</label><br />
            <input type="text" name="email" id="email" size="20" value="<?php echo $email; ?>" /><br />
            <label for="phone">Phone:</label><br />
            <input type="text" name="phone" id="phone" size="20" value="<?php echo $phone; ?>" /><br />
            <label for="date">Starting Date:</label><br />
            <input type="text" name="date" id="date" size="20" title="Click to select date" value="<?php echo $date; ?>" /><br />
            <label for="comments">Comments:</label><br />
            <textarea name="comments" id="comments" rows="5" cols="20"><?php echo $comments; ?></textarea><br />
            <label for="comments">Display Ad:</label><br />
            <input type="file" name="imagefile" /><br /><br />
            <input name="p" type="hidden" value="calc-spa-d" />
            <input name="id" type="hidden" value="<?php echo intval($_REQUEST['id']); ?>" />
            <input type="hidden" name="state_id_submit" id="state_id_submit" value=""/>           
            <input type="hidden" name="price_submit" id="price_submit" value=""/>
            <input type="hidden" name="size_submit" id="size_submit" value=""/>
            <input type="hidden" name="paper_name_submit" id="paper_name_submit" value=""/>
            <script type='javascript' >
            function setvalue(){
               document.getElementById('state_id_submit').value=document.getElementById('state_id_ajax').value;
               document.getElementById('price_submit').value=document.getElementById('price_ajax').value;
               document.getElementById('size_submit').value=document.getElementById('size_ajax').value;
               document.getElementById('paper_name_submit').value=document.getElementById('paper_name_ajax').value;
            }
            </script>
            <input type="submit" name="Submit" value="Calculate!" />
 
</form>
<iframe name="if1" src="about:blank" width="1" height="1"></iframe>
<script>
	 tId1 = setInterval('showPriceD()',200);
</script>

Open in new window

catonthecouchproductions

ASKER
Where do we stand on getting that to work, so far it doesn't carry over to the confirm page.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
catonthecouchproductions

ASKER
I made some changes, I made variables for: price, size, and state, and am using php to insert to the variable then insert in to the ID, check out my code.
    <script>
    // declare variables
    var groupText = "";
    var price     = "";
    var size      = "";
    
    <?php
    include_once ("config.php");
    if($_REQUEST["state_id"]){
        $state_id     = htmlspecialchars(stripslashes($_REQUEST["state_id"]));
        $sql          = "SELECT displayPrice,displaySize,state_id FROM spa_states WHERE state_id=$state_id";
        $query        = mysql_query($sql) or die(mysql_error());
        while($row = mysql_fetch_array($query)){
            if ($row["displayPrice"]!=""){
                print "\ngroupText='<b>$".$row["displayPrice"]." for ".$row["displaySize"]." column inche(s).</b>';\n";  
                print "\nparent.document.getElementById('GroupPrice').innerHTML=groupText;\n";
                
                // set price equal to php value
                print "\n price = '".$row["displayPrice"]."'";
                // set size equal to php value
                print "\n size = '".$row["displaySize"]."'";
                print "\nparent.document.getElementById('price').value = price;\n";
            }else{
                print "\ngroupText='No price/data for this ID.'";
            }    
        }
    }else{
        print "\ngroupText='Must have a valid ID to continue.'";
    }
    ?>
    </script>
    <?
    print "\n<input type='hidden'  id='price' value='' />";
    print "\n<input type='hidden'  id='size_ajax' value='".$size_ajax."' />";
    print "\n<input type='hidden'  id='price_ajax' value='".$price_ajax."' />";
    print "\n<input type='hidden'  id='paper_name_ajax' value='".$paper_name_ajax."' />\n";
    ?>  

Open in new window