如何在按钮单击中打开新表单?

时间:2014-09-04 06:08:23

标签: javascript php jquery ajax

嗨我正在使用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 更新按钮可用我想在该更新按钮按钮上打开一个新表单

我怎样才能实现这个目标

任何帮助将不胜感激

2 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分: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>

如果您需要更多帮助..请详细说明您的要求......