how could i open a new window using javascript inside php that holds a value of a js variable? please help. thx

Recommended Answers

I didn't understood much of what you said. But PHP cannot hold a JS var, PHP can only execute JS by writing it and JS can only execute PHP by a server request.

Is something like this you want?

<?php
    echo('<script type="text/string">window.open(....);</script>');
?>
Jump to Post

I think so. Maybe he wants to use the variable in PHP as well. I believe, you can concatenate the variable to the string in the echo in order to pass the variable value to the new window.

Jump to Post

in new page you can use php variable in javascript following way

<?php
.
.
.
$query = mysql_query("
INSERT INTO reservation VALUES('','$fname','$email','$pnum','$numofperson','$numofroom','$roomtype','$cur_date','$time2','$date_value','$stay','pending','$tot2','$tot2','0')
");
.
.
.

?>
<html>
<script lang='javascript' >
function myfunction()
{
   var firstnm="<?php echo $fname;?>";
  
   alert(firstnm);
   
}

</script>
Jump to Post

All 10 Replies

I didn't understood much of what you said. But PHP cannot hold a JS var, PHP can only execute JS by writing it and JS can only execute PHP by a server request.

Is something like this you want?

<?php
    echo('<script type="text/string">window.open(....);</script>');
?>

I think so. Maybe he wants to use the variable in PHP as well. I believe, you can concatenate the variable to the string in the echo in order to pass the variable value to the new window.

sorry for that, i'm a newbie on php and on javascript my codes looks like this
$connect = mysql_connect("localhost","root","");
mysql_select_db("clarissa_records");
$query = mysql_query("
INSERT INTO reservation VALUES('','$fname','$email','$pnum','$numofperson','$numofroom','$roomtype','$cur_date','$time2','$date_value','$stay','pending','$tot2','$tot2','0')
");
i want to insert a javascript on this part opening a new window holding the value of variable $fname, tnx a lot..

in new page you can use php variable in javascript following way

<?php
.
.
.
$query = mysql_query("
INSERT INTO reservation VALUES('','$fname','$email','$pnum','$numofperson','$numofroom','$roomtype','$cur_date','$time2','$date_value','$stay','pending','$tot2','$tot2','0')
");
.
.
.

?>
<html>
<script lang='javascript' >
function myfunction()
{
   var firstnm="<?php echo $fname;?>";
  
   alert(firstnm);
   
}

</script>

I didn't understood much of what you said. But PHP cannot hold a JS var, PHP can only execute JS by writing it and JS can only execute PHP by a server request.

Is something like this you want?

<?php
    echo('<script type="text/string">window.open(....);</script>');
?>

yes sir exactly what i
want. :)

in new page you can use php variable in javascript following way

<?php
.
.
.
$query = mysql_query("
INSERT INTO reservation VALUES('','$fname','$email','$pnum','$numofperson','$numofroom','$roomtype','$cur_date','$time2','$date_value','$stay','pending','$tot2','$tot2','0')
");
.
.
.

?>
<html>
<script lang='javascript' >
function myfunction()
{
   var firstnm="<?php echo $fname;?>";
  
   alert(firstnm);
   
}

</script>

i want to insert the javascript inside my php code, opening a new window holding the value of php variable $fname

like this sir..

$connect = mysql_connect("localhost","root","");
mysql_select_db("clarissa_records");
$query = mysql_query("
INSERT INTO reservation VALUES('','$fname','$email','$pnum','$numofperson','$numofroom','$roomtype','$cur_date','$time2','$date_value','$stay','pending','$tot','$tot','0')
");
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<script language=javascript>alert($fname)</script>
<script language=javascript>window.location='reservation1.php'</script>";
}

&nbpsp; is not required its of no use, its only useful in html code, quote your fname around quotes.

<?php
.
.
.
echo "<script language=javascript>alert('$fname');
window.location='reservation1.php';</script>";
.
.

?>

<script type="text/javascript">
<!--
function popup(url)
{
var date = "<?php echo $date1; ?>";
var width = 950;
var height = 750;
var left = (screen.width - width)/2;
var top = (screen.height - height)/2;
var params = 'width='+width+', height='+height;
params += ', top='+top+', left='+left;
params += ', directories=no';
params += ', location=no';
params += ', menubar=no';
params += ', resizable=no';
params += ', scrollbars=yes';
params += ', status=yes';
params += ', toolbar=no';
url = "printlist2.php?id="+date;
newwin=window.open(url,'windowname5', params);
if (window.focus) {newwin.focus()}
return false;
}
// -->
</script>

this is the javascript i want to insert inside my php code

var date = "<?php echo $date1; ?>";

I think this is the best way to access php in javascript. so you go ahead, I dont think you will get any problem in this.

how do i insert it in php code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.