Jump to content

Form field dynamically


jeeva

Recommended Posts

hi frnds,

 

anyone can help me?

here my problem,

i need to get form field dynamically.whenever  user click the new link the new text field has to add with the form

 

can i do this? if yes, how? or any open source is there for this?

 

 

 

thanks in advance

jeeva

 

Link to comment
Share on other sites

<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

 

 

 

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.