Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-29-2012, 10:54 PM   PM User | #1
jofrabt
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jofrabt is an unknown quantity at this point
send variable from php to html

Hi, i'm quite new with PHP, i'm trying to modify some code, what I want to do is to get the value that is calculated via php and use it on an html input text field, hr_extra, wich I wrote here in yellow color, so the user could be able to modify it, I want it to get the $totalAmount variable, but I haven't been able to parse it.

here's the code from ordercheckout.php

Code:
<?php 
	session_start();

	require_once("shared.php");
	
	//XAJAX HANDLERS
	require_once("xajax_core/xajax.inc.php");
	$xajax = new xajax();

	$xajax->register(XAJAX_FUNCTION, "xsetImage");
	
	function xsetImage($value, $id)
	{
		$objResponse = new xajaxResponse();

		if(!isset($_SESSION['images']))
		{
			$_SESSION['images'] = array();
		}
		
		if($value == 1)
		{
			$_SESSION['images'][] = $id;

		}
		else
		{
			for($i=0;$i<count($_SESSION['images']);$i++)
			{
				if($_SESSION['images'][$i] == $id)
				{
					$_SESSION['images'][$i] = 0;
					break;
				}
			}
		}
			
		
		return $objResponse;
	}
	
	$xajax->processRequest();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
	function viewPdf()
	{
		document.getElementById('order-checkout').action = 'viewpdf.php';
		document.getElementById('order-checkout').target = '_new';
		document.getElementById('order-checkout').submit();
		
	}
	
	function sendPdf()
	{
		document.getElementById('order-checkout').action = 'ordersend.php';
		document.getElementById('order-checkout').target = '_self';
		document.getElementById('order-checkout').submit();
	}
	
</script>
<?php $xajax->printJavascript(); ?>
<link rel="stylesheet" href="stylesheets/style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nox - Checkout de Orden</title>
</head>
<body>
<div id="debugger"></div>
	<div id="wrapper">
    <form id="order-checkout" action="ordersend.php" method="post">
		<fieldset>
    		<legend>Resumen de Cotizacion</legend>
            <div class="inputEntry">
            	<label class="labelL">Nombre del Cliente</label>
				<label><?php echo $_SESSION['c-name']; ?></label>
            </div>
            <div class="inputEntry">
            	<label class="labelL">Direccion</label>
				<label><?php echo $_SESSION['c-address']; ?></label>
            </div>
            <div class="inputEntry">
    	        <label class="labelS">Telefono</label>
                <label><?php echo $_SESSION['c-phone']; ?></label>
            </div>
            <div class="inputEntry">
    	        <label class="labelS">Email</label>
				<label><?php echo $_SESSION['c-email']; ?></label>
            </div>
            <div class="inputEntry">
    	        <label class="labelS">Fecha de Nacimiento</label>
				<label><?php echo $_SESSION['c-dob']; ?></label>
            </div>
            <div class="inputEntry">
            	<label class="labelS">Horas de Servicio</label>
                <input type="text" id="hours" name="hours" style="width:60px;"class="inputTextL required" value="5"/>
            </div>
            <div class="inputEntry">
            	<label class="labelS">Cotizacion desglosada</label>
				<input type="checkbox" name="des" id="des"/>
            </div>            
            <div class="inputEntry">
            	<label class="labelS">Destinatarios</label>
                <input type="text" name="dest" style="width:600px;"
                 class="inputTextL required" value="<?php echo $_SESSION['c-email']; ?>"/>
                <div class="inputEntry">
                    <label class="labelS">Hr. Extra</label>
                    <input type="text" id="hr_extra" name="hr_extra" style="width:100px;" value=""/>
				</div>
            </div>
			
            <div class="order-actions">            
                <ul>
                    <li><input type="button" value="Modificar Cliente" class="submit" 
                    onclick="document.location='clientregistry.php'"/></li>
                    <li><input type="button" value="Modificar Orden" class="submit"
                    onclick="document.location='productcatalog.php'"/></li>
                    <li><input type="button" value="Visualizar  PDF" class="submit" 
                    onclick="viewPdf()"/></li>
                    <li><input type="button" value="Finalizar y Enviar" class="submit"
                    onclick="sendPdf()"/></li>
                </ul>
            </div>

	    
        
        <div id="product-summary">
            	<div id="p-details">
                	<div>Concepto</div>
                    <div>Cantidad</div>
                    <div>Precio Unitario</div>
                    <div>Subtotal</div>
                </div>
                <div id="order-content">
                <?php
					
	$totalAmount = 0;
				//Print current Items
				for($i=0;$i<count($_SESSION['productIDS']);$i++)
				{
					if($_SESSION['productQuantities'][$i] < 1)
						continue;
					$product = getProductById($_SESSION['productIDS'][$i]);
					$subTotal = $product->price * $_SESSION['productQuantities'][$i];
					$totalAmount += $subTotal;
					
					$html .= '
					<div id="p-content">
                        <div>'.$product->name.'</div>
                        <div>'.$_SESSION['productQuantities'][$i].'</div>
                        <div>$'.number_format($product->price, 2).'</div>
                        <div>$'.number_format($subTotal, 2).'</div>
                    </div>
					
					';
				}
				echo $html;
				
				//MANDAR TOTAL 
				
				if($_SESSION['dsc'] > 0)
				{
					$html = '
					<div id="p-content">
                        <div>&nbsp;</div>
                        <div>&nbsp;</div>
                        <div style="font-weight:bold;">Descuento</div>
                        <div style="font-weight:bold;">'.number_format($_SESSION['dsc'], 2).'%</div>
                    </div>
					
					';
					
					$totalAmount = $totalAmount - ($totalAmount * ($_SESSION['dsc']/100));
					echo $html;
				}
				
				
				
				$html= '
					<div id="p-content">
                        <div>&nbsp;</div>
                        <div>&nbsp;</div>
                        <div style="font-weight:bold;">Total:</div>
                        <div style="font-weight:bold;">$'.number_format($totalAmount, 2).'</div>
                    </div>
					
					';
				//echo $totalAmount;
				echo $html;	
				?>
                </div>            	
            </div>
            
            <div>
	            <label>Imagenes para adjuntar</label>            
                <ul id="image-list">
                	<?php
					
						for($i=0;$i<count($_SESSION['productIDS']);$i++)
						{
							$html = "";
							if($_SESSION['productQuantities'][$i] > 0)	
							{
								$image = getImageByProductId($_SESSION['productIDS'][$i]);
								if(!empty($image))
								{
									$html .= '<li><input type="checkbox" name="images[]" value="'.$image->id.'"  /><img src="images/'.$image->url.'" width="150px"/></li>';
								}
								
							}
							
							echo $html;
						}
		
					?>

                </ul>                
            </div>
        </fieldset>
        
    </form>
    
    
    
    </div>
</body>
</html>
jofrabt is offline   Reply With Quote
Old 10-30-2012, 01:34 AM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Find the following code segment and INSERT the javascript that is colored red: It starts at line 165:
Code:
$totalAmount = $totalAmount - ($totalAmount * ($_SESSION['dsc']/100));
echo $html;
}
$html= '
<div id="p-content">
    <div>&nbsp;</div>
    <div>&nbsp;</div>
    <div style="font-weight:bold;">Total:</div>
    <div style="font-weight:bold;">$'.number_format($totalAmount, 2).'</div>
</div>
';
//echo $totalAmount;
echo $html;
?>
<script type="text/javascript">
  var amount_total = <?php echo $totalAmount; ?>;
  document.getElementById('hr_extra').value = '$'+amount_total;
</script>
</div>
</div>
sunfighter is offline   Reply With Quote
Old 10-30-2012, 11:21 AM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Well that only deals with a value that php printed into the page as it was being generated.

If you want a value to be transmitted from the server to the page the op will need to use ajax.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 10-30-2012, 04:42 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
@tangoforce
From everything I see the $totalAmount is generated by values in the session variables and the only open field in the html form [Hr. Extra] does not affect it. So the preprocessed value should be the final value jofrabt is looking for.
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Tags
pass variables

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:25 AM.


Advertisement
Log in to turn off these ads.