2014-09-04 91 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); 
}