在同一窗口上操作多个按钮


Multiple buttons to action on the same window

我在同一个表单上创建了两个按钮,当我单击它们时,会弹出一个新窗口。我希望他们在同一个窗口上打开已操作的表单。

在代码块中找到我的代码。

Thanks in advance

<?php
//Start session
session_start();    
//Unset the variables stored in session
unset($_SESSION['SESS_FIRST_NAME']);
unset($_SESSION['SESS_LAST_NAME']);
?>
<!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 language="Javascript">
<!--
function OnButton1()
{
    document.loginform.action = "login_exec.php"
    document.loginform.target = "_blank";    // Open in a new window
    document.loginform.submit();             // Submit the page
    return true;
}
function OnButton2()
{
    document.loginform.action = "adminLogin.php"
    document.loginform.target = "_blank";    // Open in a new window
    document.loginform.submit();             // Submit the page
    return true;
}
-->
</script>
<noscript>You need Javascript enabled for this to work</noscript>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Document</title>
</head>
<body>
    <?php
    if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && 
count($_SESSION['ERRMSG_ARR']
) >0 ) {
echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<body bgcolor="green">
<form name="loginform" method="post">
<br/><br/><br/><br/><br/><br/><br/>
<table width="309" border="0" align="center" cellpadding="2" cellspacing="5">
<tr>
<td colspan="2">
<!--the code bellow is used to display the message of the input validation-->
</td>
</tr>
<tr>
<td><div align="right">Username</div></td>
<td><input name="username" type="text" /></td>
</tr>
<tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="password" type="password" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><INPUT type="button" value="Login" name=button onclick="OnButton1();"><br/><br/>
<INPUT type="button" value="Click to Login as Admin" name=button onclick="OnButton2();"></td>
</tr>
</table>
</form>

</body>
</html>

在你的函数OnButton1和OnButton2中,你将目标设置为空白(打开一个新窗口)。

代码:

document.loginform.target = "_blank";    // Open in a new window

如果你想让表单在同一个窗口中执行操作,你必须将目标设置为"_self"。

我不知道该怎么说我在想什么,所以我希望有人能帮助我编辑后,但你不需要将函数附加到一个类或一个按钮的id像这样

<input type=submit id=button1/><input type=submit id=button2/>
<script>
$('#button1').click(function() {
   document.loginform.action = "login_exec.php"
   document.loginform.target = "_blank";    // Open in a new window
   document.loginform.submit();             // Submit the page
   return true;
});
$('#button2').click(function() {
   document.loginform.action = "adminLogin.php"
   document.loginform.target = "_blank";    // Open in a new window
   document.loginform.submit();             // Submit the page
   return true;
});
</script>

您甚至可以通过ajax调用

启动登录PHP脚本