Php 如何将变量从表单传递到javascript弹出表单?
我有一个带有按钮的表单,可以打开一个javascript/css弹出窗口。在弹出窗口中,我有一个文本区域,用于向数据库字段添加注释。问题是我需要从主页(调用弹出窗口的主页)向它传递一个值,该值将标识数据库中要更新的条目。但我一直在努力让它发挥作用。这是我的密码。我需要将变量发送到update.php页面。请帮忙Php 如何将变量从表单传递到javascript弹出表单?,php,javascript,html,Php,Javascript,Html,我有一个带有按钮的表单,可以打开一个javascript/css弹出窗口。在弹出窗口中,我有一个文本区域,用于向数据库字段添加注释。问题是我需要从主页(调用弹出窗口的主页)向它传递一个值,该值将标识数据库中要更新的条目。但我一直在努力让它发挥作用。这是我的密码。我需要将变量发送到update.php页面。请帮忙 <?php ini_set('display_errors',1); error_reporting(E_ALL); if(isset($_GET['sort']) &
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
if(isset($_GET['sort']) && isset($_GET['col']) ){
$order = $_GET['sort'];
$column = $_GET['col'];
}
else{
$order = 'ASC';
$column = 'cron_id';
}
$page = 'Testing Site';
require_once('includes/head.php');
require_once('includes/mysql.php');
require_once('includes/class.tdcron.php');
require_once('includes/class.tdcron.entry.php');
date_default_timezone_set('America/Los_Angeles');
$result = mysql_query("SELECT * FROM cron WHERE active=1 ORDER BY $column $order") or die (mysql_error());
mysql_close();
$pass = "<img src='images/Checked.png' alt='Pass' width='16' height='16'/>";
$fail = "<img src='images/Stop.png' alt='Failed' width='16' height='16'/>";
$warn = "<img src='images/Warning.png' alt='Warning' width='16' height='16' />";
$com = "<img src='images/pencil.png' alt='Warning' width='16' height='16' />";
echo "<div id='tableContainer' class='tableContainer'>";
echo "<table width='100%' border='0' padding='0' cellpadding='0' cellspacing='0' class='scrollTable'>";
echo "<thead class='fixedHeader'>";
echo "<tr>";
if ($order=="ASC") { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=DESC&col=ok\" title=\"Sort the records in descending order\">Status</a></th>"; }
else { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=ASC&col=ok\" title=\"Sort the records in ascending order\">Status</a></th>"; }
echo '<th><a href="#">Schedule</a></th>';
if ($order=="ASC") { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=DESC&col=job\" title=\"Sort the records in descending order\">Job</a></th>"; }
else { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=ASC&col=job\" title=\"Sort the records in ascending order\">Job</a></th>"; }
echo '<th><a href="#">Description</a></th>';
if ($order=="ASC") { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=DESC&col=destination\" title=\"Sort the records in descending order\">Destination</a></th>"; }
else { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=ASC&col=destination\" title=\"Sort the records in ascending order\">Destination</a></th>"; }
echo '<th><a href="#">Errors</a></th>';
if ($order=="ASC") { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=DESC&col=jobtype\" title=\"Sort the records in descending order\">Job Type</a></th>"; }
else { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=ASC&col=jobtype\" title=\"Sort the records in ascending order\">Job Type</a></th>"; }
if ($order=="ASC") { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=DESC&col=catagory\" title=\"Sort the records in descending order\">Category</a></th>"; }
else { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=ASC&col=catagory\" title=\"Sort the records in ascending order\">Category</a></th>"; }
if ($order=="ASC") { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=DESC&col=ran_at\" title=\"Sort the records in descending order\">Last Ran</a></th>"; }
else { echo "<th><a href=\"" . $_SERVER["PHP_SELF"] . "?sort=ASC&col=ran_at\" title=\"Sort the records in ascending order\">Last Ran</a></th>"; }
echo '<th><a href="#">Next Run</a></th>';
echo '<th><a href="#">Log</a></th>';
echo '</tr></thead><tbody class="scrollContent">';
while($row = mysql_fetch_array($result)){
if($row['ok'] == 1){$status = $pass;}
elseif($row['ok'] == 0){$status = $fail;}
else{$status = $warn;}
echo '<tr>';
echo
'<td>
**<form name="frm_comment" action="" onsubmit="return false;" >' . $status . ' ' .
'<input type="image" src="images/pencil.png" onclick="popup_show(\'popup\', \'popup_drag\', \'popup_exit\', \'mouse\', -10, -5);" width=\'16\' height=\'16\' />
</form>**
</td>';
echo '<td>' . $row['schedule'] . '</td>';
echo '<td>' . $row['job'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['destination'] . '</td>';
echo '<td>' . $row['errormsgs'] . '</td>';
echo '<td>' . $row['jobtype'] . '</td>';
echo '<td>' . $row['catagory'] . '</td>';
echo '<td>' . date('D M d @ g:i A', $row['ran_at']) . '</td>';
echo '<td>' . date('D M d @ g:i A', tdCron::getNextOccurrence($row['mhdmd'])) . '</td>';
echo "<td><a href='log/" . $row['log'] . "' target='_blank' >View Log</a></td>";
echo '</tr>';
}
echo '</tbody>';
echo "</table>";
echo "</div>";
// ***** Popup Window ****************************************************
echo'<div class="sample_popup" id="popup" style="display: none;">
<div class="menu_form_header" id="popup_drag">
<img class="menu_form_exit" id="popup_exit" src="images/form_exit.png" alt="Close Form" /> Comments
</div>
<div class="menu_form_body">
<form name="up" action="update.php" onsubmit="return validateForm()" method="post" >
<input type="hidden" name="' . $row['job'] . '" />
<table>
<tr>
<td><textarea class="field" onfucus="select();" name="comment" rows="8" cols="44"></textarea>
</tr>
<tr>
<td align="right" ><br /><input class="btn" type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
</div>';
require_once('includes/footer.php');
?>
结束Javascript代码
CSS代码开始
div.sample_popup { z-index: 1; }
div.sample_popup div.menu_form_header
{
border: 1px solid black;
border-bottom: none;
width: 400px;
height: 20px;
line-height: 19px;
vertical-align: middle;
background: url('../images/form_header.png') no-repeat;
text-decoration: none;
font-family: Times New Roman, Serif;
font-weight: 900;
font-size: 13px;
color: #FFFFFF; /*#206040;*/
cursor: default;
}
div.sample_popup div.menu_form_body
{
width: 400px;
height: 200px;
border: 1px solid black;
background: url('../images/form.png') no-repeat left bottom;
}
div.sample_popup img.menu_form_exit
{
float: right;
margin: 4px 5px 0px 0px;
cursor: pointer;
}
div.sample_popup table
{
width: 100%;
border-collapse: collapse;
}
div.sample_popup th
{
width: 1%;
padding: 0px 5px 1px 0px;
text-align: left;
font-family: Times New Roman, Serif;
font-weight: 900;
font-size: 13px;
color: #004060;
}
div.sample_popup td
{
width: 99%;
padding: 0px 0px 1px 0px;
}
div.sample_popup form
{
margin: 0px;
padding: 8px 10px 10px 10px;
}
div.sample_popup input.field
{
width: 95%;
border: 1px solid #808080;
font-family: Verdana, Sans-Serif;
font-size: 12px;
}
div.sample_popup input.btn
{
margin-top: 2px;
border: 1px solid #808080;
background-color: #DDFFDD;
font-family: Verdana, Sans-Serif;
font-size: 11px;
}
CSS代码结束您使用的是一个JS/CSS弹出窗口,因此只需在调用
popup_show()
时传递$row['job']
(假设您能够修改或重载该JS函数),然后用Javascript将其填充到弹出HTML的隐藏字段中。按照现在的方式,您必须为结果集中的每一行复制一次弹出式HTML块,以使其正常工作。您是否尝试过定义一个窗口。在一个js代码上打开document.createElement
一个新表单,并使用hiddenField.setAttribute
定义$\u POST
元素?不确定它是否有效,但值得花点时间在上面。另外,为了DOS的缘故,尝试使用html而不是htm:)您可以发布修改后的popup_show()函数的代码吗?
div.sample_popup { z-index: 1; }
div.sample_popup div.menu_form_header
{
border: 1px solid black;
border-bottom: none;
width: 400px;
height: 20px;
line-height: 19px;
vertical-align: middle;
background: url('../images/form_header.png') no-repeat;
text-decoration: none;
font-family: Times New Roman, Serif;
font-weight: 900;
font-size: 13px;
color: #FFFFFF; /*#206040;*/
cursor: default;
}
div.sample_popup div.menu_form_body
{
width: 400px;
height: 200px;
border: 1px solid black;
background: url('../images/form.png') no-repeat left bottom;
}
div.sample_popup img.menu_form_exit
{
float: right;
margin: 4px 5px 0px 0px;
cursor: pointer;
}
div.sample_popup table
{
width: 100%;
border-collapse: collapse;
}
div.sample_popup th
{
width: 1%;
padding: 0px 5px 1px 0px;
text-align: left;
font-family: Times New Roman, Serif;
font-weight: 900;
font-size: 13px;
color: #004060;
}
div.sample_popup td
{
width: 99%;
padding: 0px 0px 1px 0px;
}
div.sample_popup form
{
margin: 0px;
padding: 8px 10px 10px 10px;
}
div.sample_popup input.field
{
width: 95%;
border: 1px solid #808080;
font-family: Verdana, Sans-Serif;
font-size: 12px;
}
div.sample_popup input.btn
{
margin-top: 2px;
border: 1px solid #808080;
background-color: #DDFFDD;
font-family: Verdana, Sans-Serif;
font-size: 11px;
}