I have written a javascript to generate textbox dynamically.
Code:
function addtextbox(val)
{
var foo = document.getElementById('fooBar');
var num = (document.getElementById('cnt').value -1 + 2);
ingrds[num]= val;
var newdiv = document.createElement('div');
var divIdName = 'divid'+num;
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = '<input type="text" size="15" id="' + ingrds[num] + '" value="' + val + '"><a href="javascript:remove('+divIdName+')">Remove</a>';
foo.appendChild(newdiv);
}
//function to remove dynamically added textbox
function remove(dId)
{
var foo = document.getElementById('fooBar');
foo.removeChild(dId);
}
Whenever remove function is called i want to get the value of the textbox before removing it. How to go about it. Thanks in advance.
input elements can have their value access using the
input.valueproperty.The same goes for textarea element (textbox).
EDIT
can be changed to
no your function ca use the parameter