jbadia
asked on
print php variable with javascript
Hello boys. I've a question.
I have a php that sends a mail and I wish thast when I click a button, it cleans the page with javascript and prins a php variable.
This is part of my page:
$query_result = mysql_query("SELECT articulo, marca, tipusRoba, hd, referencia, tallas, color, precio, cantidad, SUM(cantidad*precio) AS subtotal FROM ".$session[taula]." group by id");
$filecontents = '<table width=800 border=0 align=center cellpadding=0 cellspacing=1 bgcolor=#990000><tr><td bgcolor=#FFFFFF>Datos del cliente:';
$filecontents .= '</td></tr></table><table width=800 border=0 align=center cellpadding=0 cellspacing=1 bgcolor=#990000><tr><td bgcolor=#FFFFFF>';
$filecontents .= '<br><strong>Nombre y apellidos:</strong> '.$nombre.'';
$filecontents .= '<br><strong>dirección:</s trong> '.$direccion.', '.$numero.', '.$piso.' - '.$puerta.'';
$filecontents .= '<br><strong>Población:</s trong> '.$poblacion.' - '.$cp.'';
$filecontents .= '<br><strong>Província:</s trong> '.$provincia.'';
$filecontents .= '<br><strong>Teléfono:</st rong> '.$telefono.' -<strong> E-Mail: </strong>'.$mail.'';
$filecontents .= '<br><strong>Anotación:</s trong><br> '.$nota.'< br><br>';
$filecontents .= '</td></tr></table><table width=800 border=0 align=center cellpadding=0 cellspacing=1 bgcolor=#990000><tr><td bgcolor=#FFFFFF>PEDIDO:';
$filecontents .= '</td></tr><table cellpadding=0 cellspacing=1 bgcolor=#990000 width=800 border=0 align=center><tr><td class=camp_edt>articulo</t d><td class=camp_edt>marca</td>< td class=camp_edt>tipo</td><t d class=camp_edt>sexo</td><t d class=camp_edt>refer.</td> <td class=camp_edt>talla</td>< td class=camp_edt>color</td>< td class=camp_edt>precio</td> <td class=camp_edt>cant.</td>< td class=camp_edt>subt.</td>
</tr><tr>';
while($row = mysql_fetch_row($query_res ult))
$filecontents .= '<td bgcolor=#FFFFFF>'.implode( '</td><td bgcolor=#FFFFFF>', $row).''.'</tr><tr>';
$filecontents .= '</tr></table>';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>FINALIZAR PEDIDO</title>
<script>
function clearMe()
{
var _s=top;
var _d=_s.document;
var llista = <?echo $filecontents;?>
_d.open();
_d.write("");
_d.close();
}
</script>
Then, I press a button and calls the function clearMe.
What can I do to print the variable $filecontents when the screen is clear?
Thanks a lot
Jordi
I have a php that sends a mail and I wish thast when I click a button, it cleans the page with javascript and prins a php variable.
This is part of my page:
$query_result = mysql_query("SELECT articulo, marca, tipusRoba, hd, referencia, tallas, color, precio, cantidad, SUM(cantidad*precio) AS subtotal FROM ".$session[taula]." group by id");
$filecontents = '<table width=800 border=0 align=center cellpadding=0 cellspacing=1 bgcolor=#990000><tr><td bgcolor=#FFFFFF>Datos del cliente:';
$filecontents .= '</td></tr></table><table width=800 border=0 align=center cellpadding=0 cellspacing=1 bgcolor=#990000><tr><td bgcolor=#FFFFFF>';
$filecontents .= '<br><strong>Nombre y apellidos:</strong> '.$nombre.'';
$filecontents .= '<br><strong>dirección:</s
$filecontents .= '<br><strong>Población:</s
$filecontents .= '<br><strong>Província:</s
$filecontents .= '<br><strong>Teléfono:</st
$filecontents .= '<br><strong>Anotación:</s
$filecontents .= '</td></tr></table><table width=800 border=0 align=center cellpadding=0 cellspacing=1 bgcolor=#990000><tr><td bgcolor=#FFFFFF>PEDIDO:';
$filecontents .= '</td></tr><table cellpadding=0 cellspacing=1 bgcolor=#990000 width=800 border=0 align=center><tr><td class=camp_edt>articulo</t
</tr><tr>';
while($row = mysql_fetch_row($query_res
$filecontents .= '<td bgcolor=#FFFFFF>'.implode(
$filecontents .= '</tr></table>';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>FINALIZAR PEDIDO</title>
<script>
function clearMe()
{
var _s=top;
var _d=_s.document;
var llista = <?echo $filecontents;?>
_d.open();
_d.write("");
_d.close();
}
</script>
Then, I press a button and calls the function clearMe.
What can I do to print the variable $filecontents when the screen is clear?
Thanks a lot
Jordi
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
www.activewidgets.com/javascript.forum.4257.6/javascript-and-php-variables.html "ActiveWidgets • javascript and php variables • javascript php variable"
ASKER
Code goes right, but it doesn't print my variable $filecontents, why? perhaps because is a multiline variable?
Jordi
Jordi
I don't think you need function clearMe
Try replacing it with a new function that has the code I gave you, or use the code without putting it in a function.
Try replacing it with a new function that has the code I gave you, or use the code without putting it in a function.
ASKER
yes, as i said, the your code goes right with another variable, but not with the variable I said, $filecontents.
This is how I have now:
<script>
function clearMe()
{
document.write(<?php print "'".$nombre."'"; ?>);
}
</script>
If I put:
</script>
<script>
function clearMe()
{
document.write(<?php print "'".$filecontents."'"; ?>);
}
</script>
It don't go. Can You explain me why? Thanks a lot.
Jordi
This is how I have now:
<script>
function clearMe()
{
document.write(<?php print "'".$nombre."'"; ?>);
}
</script>
If I put:
</script>
<script>
function clearMe()
{
document.write(<?php print "'".$filecontents."'"; ?>);
}
</script>
It don't go. Can You explain me why? Thanks a lot.
Jordi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use the javascript urlencode to code up the $fileconents, then urldecode to print. this will sort out any newline problems.
ASKER
Thank you guys.
50 to answer in part my question and 200 to solve the problem.
jordi
50 to answer in part my question and 200 to solve the problem.
jordi
'<br>', not "\n" was in the code you posted here, so it escaped my attention 'til last night.
Good job nitinsawhney!
Good job nitinsawhney!