Monday 22 April 2013

Add new field on click in forms


<?php
if(isset($_POST['sub']))
{
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
?>
<html>
<head>
<style>
p{overflow:visible; }

</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
function appendText()
{

var txt3=document.createElement("p");
txt3.innerHTML="<input type='text' name='file[]'  />";               // Create text with DOM
$("div").append(txt3);        // Append new elements
}
</script>
</head>




<body>
<button onclick="appendText()">Append text</button>
<p>Add files here.</p>
<form action="" method="post" name="form1" >


<div></div>
<input type="submit" name="sub" />
</form>
</body>
</html>

No comments:

Post a Comment