2014-05-07 48 views
0

l在同一個窗體上創建了兩個按鈕,當我單擊其中每個按鈕時,彈出一個新窗口。我會希望他們在同一個窗口中打開動作表單。在同一個窗口上動作的多個按鈕

在代碼塊中查找我的代碼。

在此先感謝

<?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> 
+0

我想我得到了答案http://www.w3schools.com/jsref/prop_form_target.asp – Guderz90

回答

0

在你的函數OnButton1和OnButton2你的目標設定爲形式的空白(打開一個新窗口)。

您的代碼:

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

你必須設定目標爲「_self」如果你想要的形式來執行在同一窗口的作用。

+0

謝謝,這是我被告知使用鏈接。我非常感謝你的幫助 – Guderz90

0

我不知道如何說什麼即時通訊思想,所以我希望有人能幫助我的後編輯,但不要你需要的功能附加到一個類或者一個按鈕,像這樣

<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> 
的ID

你甚至可以通過ajax調用登錄php腳本

+0

上面發佈的代碼l工作正常,我只是希望它在同一窗口中打開(使用「_self」而不是「_blank」) – Guderz90

相關問題