[英]Adding Form tag to html elements created by innerHTML
我正在动态创建html元素:一个文本框和一个提交按钮 ,在提交时应转到php代码并将数据放置在数据库中。
但是,如果有人可以告诉我我要去哪里错了,PHP部分将无法正常工作
<html>
<head>
<title>My first PHP page</title>
<script>
function addsubdomain()
{
document.getElementById('subdomain').innerHTML +="<form id='form1' method='post' action='new.php'> \n\
<input type='text' id='textid' name='subdomain' value='' /><br /> \n\
<input type='button' id='button2' name='submit2' value='submit'/></form>";
}
</script>
</head>
<body>
<input type="button" id="button1 "name="submit1" value="Add SubDomain" onclick="addsubdomain();"/>
<div id="subdomain"></div>
<?php
if(isset($_POST['submit2']))
{
echo "hii";// Not working not coming here
echo $_POST['subdomain'];
// Insert Query
}
?>
</body>
</html>
当前在您的javascript中,您的动态按钮类型是button,因此它不提交表单。 因此,在javascript中将您的type ='button'更改为type ='submit'。 即像这样改变它
document.getElementById('subdomain').innerHTML +="<form id='form1' method='post' action='new.php'> <input type='text' id='textid' name='subdomain' value='' /><br /> <input type='submit' id='button2' name='submit2' value='submit'/></form>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.