2014-09-04 54 views
0

嗨,我使用的PHP,我使用的是Ajax我從數據庫中檢索數據,無需重新加載頁面我現在正在同一頁面上獲取數據我希望當我得到的數據我以表格格式檢索那麼當我點擊時有更新按鈕在更新按鈕的新形式應打開如何在點擊按鈕中打開新表單?

這裏是代碼

的index.php

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<script type="text/javascript"> 
function fun() 
{ 
var exam=new XMLHttpRequest(); 
exam.onreadystatechange=function() 
{ 
    if(exam.readyState==4) 
    { 
     document.getElementById("res").innerHTML=exam.responseText; 
    } 
} 
exam.open("GET","rat_test.php?name=pramod",true); 
exam.send(null); 
} 
</script> 
</head> 
<body> 
<form action="" method="post" id="form" name="form"> 
<table> 
<tr> 
<td></td><td><input type="button" onclick="fun();" value="getvalue" /> 
</td></tr> 
<div id="res"></div> 
</table> 
</form> 
</body> 
</html> 

rat_test.php

<table border="1"> 
    <tr> 
    <th scope="col">ID</th> 
    <th scope="col">Name</th> 
    </tr> 
<?php 
include("connection.php"); 
$sel="select * from info"; 
$res=mysql_query($sel); 
while($fet=mysql_fetch_array($res)) 
{ ?> 
<tr> 
<td><input type="checkbox" name="users[]" value="<?php echo $row["id"]; ?>" ></td> 
    <td><?php echo $fet['id']; ?></td> 
    <td><?php echo $fet['name']; ?></td> 

    </tr> 
<?php } 
?> 
</table> 
<form action="" method="post" id="form" name="form"> 
<table> 
<tr> 
<td></td><td><input type="button" onclick="fun()1;" value="Update" /> 
</td></tr> 
</table> 
</form> 

在這裏test_rat.php一個更新按鈕可我想打開一個新的窗體上更新按鈕按鈕

我怎樣才能做到這一點

任何幫助將不勝感激

+0

要麼得到使用Ajax的新的形式或者用JavaScript的飛行 – Shadow 2014-09-04 06:12:38

+0

創建我怎麼能拿ü可以請寫一些代碼 – 2014-09-04 06:13:37

回答

0

您還沒有明確提到你想要的這裏..

據我瞭解,你要打開更新按鈕的點擊表格中打開窗體

我做了同樣的...

只需要用下面的代碼更新rat_test.php ...

<table border="1"> 
    <tr> 
    <th scope="col">ID</th> 
    <th scope="col">Name</th> 
    </tr> 
<?php 
include("connection.php"); 
$sel="select * from info"; 
$res=mysql_query($sel); 
while($fet=mysql_fetch_array($res)) 
{ ?> 
<tr> 
<td><input type="checkbox" name="users[]" value="<?php echo $row["id"]; ?>" ></td> 
    <td><?php echo $fet['id']; ?></td> 
    <td><?php echo $fet['name']; ?></td> 

    </tr> 
<?php } 
?> 
</table> 

<table> 
<tr> 
<td></td><td><input type="button" onclick="document.getElementById('updateForm').style.display='block'" value="Update" /> 
</td></tr> 
</table> 
<div id="updateForm" style="display:none"> 
<form action="" method="post" id="form" name="form"> 
    <table border="1"> 
    <tr> 
    <th scope="col">ID</th> 
    <th scope="col"><input type="text"></th> 

    <tr> 
    <th scope="col">Name</th> 
    <th scope="col"><input type="text"></th> 
    </tr></tr> 
</form></div> 

如果您需要更多的幫助..please闡述你的要求......

+0

@when新窗體打開之前應該隱藏 – 2014-09-04 06:44:37

+0

好吧,您需要在索引頁中將以前的窗體ID設置爲id =「preform」,並將rat_test.php更新爲line document.getElementById('updateForm')。style.display ='block' ,的document.getElementById( '預成型件')。的style.display = '無' – Brijesh 2014-09-04 06:52:16

0

您可以使用ajax從後端獲取新表單,或者使用javascript創建新表單。 在潛水之前,請做一些關於如何使用javascript創建元素的研究。

Fiddle demo

function makeForm(){ 
var ele = document.createElement("input"); 
ele.setAttribute("type","text"); 
ele.setAttribute("class" , "your class"); 
ele.setAttribute("name" , "username"); 

var ele2 = document.createElement("input"); 
ele2.setAttribute("type","password"); 
ele2.setAttribute("class" , "your class"); 
ele2.setAttribute("name" , "password"); 


document.body.appendChild(ele); 
document.body.appendChild(ele2); 
}