danbopes
05-29-2006, 04:17 AM
I have this as my code:
function add_option(obj,question,option)
{
var newInput = document.createElement('input');
newInput.type = 'text';
newInput.className = 'form';
newInput.name = 'Q' + question + ' O' + option;
var newTxt = document.createTextNode('Option ' + option + ':');
obj.parentNode.insertBefore(newTxt,obj);
obj.parentNode.insertBefore(document.createElement('br'),obj);
obj.parentNode.insertBefore(newInput,obj);
obj.parentNode.insertBefore(document.createElement('br'),obj);
/////////////////////////////////////////////////////////
//obj.onclick = add_option(obj,question,(option+1));
/////////////////////////////////////////////////////////
}
The problem that I am having is, if I uncomment this line, when I click on the button it goes into a repeating loop because I believe javascript still thinks the button is pushed down. I need to have it change the button so that when I click it the add_option adds the 3rd option or the 4th, not always the first.
function add_option(obj,question,option)
{
var newInput = document.createElement('input');
newInput.type = 'text';
newInput.className = 'form';
newInput.name = 'Q' + question + ' O' + option;
var newTxt = document.createTextNode('Option ' + option + ':');
obj.parentNode.insertBefore(newTxt,obj);
obj.parentNode.insertBefore(document.createElement('br'),obj);
obj.parentNode.insertBefore(newInput,obj);
obj.parentNode.insertBefore(document.createElement('br'),obj);
/////////////////////////////////////////////////////////
//obj.onclick = add_option(obj,question,(option+1));
/////////////////////////////////////////////////////////
}
The problem that I am having is, if I uncomment this line, when I click on the button it goes into a repeating loop because I believe javascript still thinks the button is pushed down. I need to have it change the button so that when I click it the add_option adds the 3rd option or the 4th, not always the first.