html and some javascript. It works well. I have a preview button in which I want to take the value from a textbox and display it in a child window. My script for popping up the child window works well, I just can't seem to get the value of the textbox passed to the child window. I have posted the javascript, the html for the textbox and coding from my child window. The value that I am passing is html code. Any help appreciated.... <table align="center">
<tr><td><textarea id="myhtml" name="supoffers" cols="80" rows="20"></textarea></td></tr>
</table>
.<script type="text/javascript" language="javascript">
var passVariable;
function mkPreview()
{
var passVariable= document.getElementById("myhtml").value;
window.open('preview.html', 'Preview', 'width=600, height=600,left=70, top=70 scrollbars=yes resizable=yes menubar=no');
}
</script>
<script>
document.write('opener.passVariable');
</script>
var passVariable= document.getElementById("myhtml").innerHTML;
<?php
require_once ("Includes/dbconfig.php");
include("Includes/session.php");
// Create database connection
$databaseConnection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($databaseConnection->connect_error)
{
die("Database selection failed: " . $databaseConnection->connect_error);
}
$baderr= "";
// check button action section
// user has click preview button
if (isset($_POST['preview']))
{
// header ("Location:saveoffer.php");
}
// user has click clear button
if (isset($_POST['clear']))
{
header ("Location:saveoffer.php");
}
// user has click on cancel button
if (isset($_POST['cancel']))
{
header ("Location:menu.php");
}
// user has click on main menu button
if (isset($_POST['main']))
{
header ("Location:menu.php");
}
// user has click on the save button
if (isset($_POST['submit']))
{
// intialize error message
$baderr= "";
// section to pull values from form
// country
$country = $_POST["country"];
//get stdmarketing value from the lookuptable
$query = "select StdMarketLabel FROM countries where Country='$country'";
$result = $databaseConnection->query($query);
while($row = $result->fetch_assoc())
{
$countrylbl = $row["StdMarketLabel"];
}
//travel
$travel = $_POST["travel"];
$query = "select StdMarketLabel FROM traveltypes where travel='$travel'";
$result = $databaseConnection->query($query);
while($row = $result->fetch_assoc())
{
$travellbl = $row["StdMarketLabel"];
}
// pulling html code pasted into textarea
$rawoffer = $_POST['supoffers'];
$goodoffer = htmlentities($rawoffer,ENT_QUOTES);
$supplerid = $_SESSION["SupplierId"];
$sqlsupplierid = $_SESSION["MsId"];
$suppliername = $_SESSION["SupplierName"];
//check to make sure they have chosen atleast one tag
// start of new coding section
if (($country == 'None Selected' and $travel == 'None Selected') or ($goodoffer == ''))
{
$baderr = "ERRORS:<BR>YOU MUST SELECT AT ATLEAST ONE TAG FOR SEARCHING.<BR>YOU MUST ENTER HTML CODING.";
}else{
// end of new coding section
$baderr = "";
$databaseConnection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($databaseConnection->connect_error)
{
die("Database selection failed: " . $databaseConnection->connect_error);
}else{
// if they have chosen an option then insert record
$sql = "insert into supplierlibrary(RecId,Name,SupplierPk,CountryStdMarket,
Country,TravelStdMarket,Travel,CampMsgBody)
values($supplerid,'$suppliername', $sqlsupplierid,'$countrylbl','$country','$travellbl','$travel','$goodoffer')";
$res= $databaseConnection->query($sql);
if (!$res)
{
$baderr = "ERROR<BR>FAILED TO INSERT RECORD<br>ERROR CODE:".$sql ."<BR><BR>" .$databaseConnection->error;
echo "<h7 style='color:#e80c4d;'>$baderr</h7>";
// echo "ERROR FAILED TO INSERT RECORD";
// echo "<BR><BR>";
// echo "ERROR<BR>" .$sql ."<BR><BR>" .$databaseConnection->error;
// allowed back into coding
}else{
$baderr = "RECORD WAS SAVED SUCCESSFULLY";
echo "<h7 style='color:'red';alignment-adjust: 'middle'>$baderr</h7>";
// moved here on 07-03
header ("Location:saveoffer.php");
}
mysqli_close($databaseConnection);
$baderr = "";
}
}
} else {
// $baderr = "Username/password combination is incorrect. Please try again";
}
?>
<script type="text/javascript" language="javascript">
var passVariable;
function mkPreview() {
var passVariable = document.getElementById("myhtml").value;
// document.write(passVariable); ///this writes on parent page - saveoffer.php...but need it to do it on child page - preview page
window.open('preview.html', 'Preview', 'width=600, height=600,left=70, top=70 scrollbars=yes resizable=yes menubar=no');
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Supplier Save Offer to Library</title>
<link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body class="bodybg">
<form action="saveoffer.php" method="post">
<br><br>
<table align="center">
<tr><td>Select any of the following tags to be for searching later.<br>You MUST choose atleast one.</br:>:</td></tr>
<tr><td colspan="2"> <?php
if (isset($_POST['submit']))
{
echo "<h7 style='color:#e80c4d;'>$baderr</h7>";
} ?>
</td></tr>
<tr><td align="right">Country:</td>
<td align="left">
<select name="country">
<option value="None Selected" selected>Choose One</option>
<?php
$query = "select * FROM countries order by Country";
$result = $databaseConnection->query($query);
while($row = $result->fetch_assoc())
{
?><option value="<?php echo $row["Country"];?>"><?php echo $row["Country"];?></option>
<?php } ?>
</select>
</td>
<td align="right">Travel Type:</td>
<td align="left">
<select name="travel">
<option value="None Selected" selected>Choose One</option>
<?php
$query = "SELECT * FROM traveltypes order by Travel";
$result = $databaseConnection->query($query);
while($row = $result->fetch_assoc())
{
?>
<option value="<?php echo $row["Travel"];?>"><?php echo $row["Travel"];?></option>
<?php } ?>
</select>
</td></tr>
</table>
<br><br>
<table align="center">
<tr><td>Paste HTML Code in textbox below</td></tr></table>
<table align="center">
<tr><td align="center">
<input type="submit" name="submit" value="Save" src="images/Save.jpg"/></td>
<td align="center"><input type="submit" name="cancel" value="Cancel" src="images/Cancel.jpg"/></td>
<td align="center"><input type="submit" name="clear" value="Clear Form" src="images/Clear.jpg"/></td>
<td align="center"><input type="button" value="Preview Offer" onclick="javascript:mkPreview();" src="images/PreviewOffer.jpg"/></td>
<td align="center"> <input type="submit" name="main" value="Main Menu" src="images/MainMenu.jpg"/></td>
</td>
</tr></table>
<br>
<table align="center">
<tr><td><textarea id="myhtml" name="supoffers" cols="80" rows="20"></textarea></td></tr>
</table>
</form>
</body>
</html>
<script>
document.write(opener.passVariable);
</script>
<script type="text/javascript">
function gup( name,context )
{
if(!context)
context=window.location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "(^|[\\?]|&(amp;)?)"+name+"=([^&#]*)";
var regex = new RegExp( regexS,"" );
var results = regex.exec( context );
if( results == null )
return "";
else
return decodeURIComponent(results[3]);
}
var data = gup('data', location.href);
alert( data );
</script>
document.write( window.opener.document.savoffer.php.supoffers.value );
var the_form = window.opener.forms["f1"];
// assuming you also have <input name="firstName"/><input name="lastName"/> in the <form>
document.write( the_form.firstName.value);
document.write( the_form.lastName.value);
document.write( the_form.supoffers.value);
http://sscce.org/