Jump to content

Form field dynamically


jeeva

Recommended Posts

<script language="JavaScript" type="text/javascript">

function changeIt()

{

var i = 1;

my_div.innerHTML = my_div.innerHTML +"<br> ><input type='text' name='others'+ i>"

</script>

place te div tags in the form where u want te field to appear.

eg: <div id="my_div"></div>

//call this function on a onclick event of te link

 

 

 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>yoshi</title>
<script type="text/javascript">
<!--

function addEvent()
{
var ni = document.getElementById('dadiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "<input type=\"text\" name=\"hello\">";
ni.appendChild(newdiv);
}

function removeEvent(divno)
{
var d = document.getElementById('dadiv');
var olddiv = document.getElementById(divno);
d.removeChild(olddiv);
}

//-->
</script>
</head>

<body>
  <input type="hidden" value="0" id="theValue" />
  <p><a href="javascript:;" onclick="addEvent();">click here to add</a></p>
  <div id="dadiv"> </div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.