leatherback
Technical User
Dear All,
In continuation of my previous thread, I now face a problem with an onchange() call.
Casically I am building a form using javascript, and when a user changes the second-last field in the form, another row of formfields is added to the form. The first row is added using an onload event, without trouble. Adding the rows manually (By pressing a button) works fine too. however, when i call the function with the onchange it doesn't work in IE or Opera (FF works).
The js:
The form elements that are inserted:
and the two way of calling:
Automatically: <input type="text" name="amount" onChange="javascript:moreFields(); " />
Bu this button: <input type="button" id="moreFields" value="Give me more fields!" />
Anybody has a keen eye and spots the problem?
Thanks so much!
J.
In continuation of my previous thread, I now face a problem with an onchange() call.
Casically I am building a form using javascript, and when a user changes the second-last field in the form, another row of formfields is added to the form. The first row is added using an onload event, without trouble. Adding the rows manually (By pressing a button) works fine too. however, when i call the function with the onchange it doesn't work in IE or Opera (FF works).
The js:
Code:
var counter = 0;
function init() {
document.getElementById('moreFields').onclick = moreFields;
moreFields();
}
function moreFields() {
counter++;
var newFields = document.getElementById('ingredientroot').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
if(theName)
{
newField[i].name = theName + counter;
newField[i].id = theName + counter;
}
}
var insertHere = document.getElementById('writeroot');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
window.onload = moreFields;
window.onload = init;
The form elements that are inserted:
Code:
<div id=\"ingredientroot\" style=\"display: none\">
<input type=\"text\" name=\"ingredient\" id=\"ingredient\" onkeyup=\"searchSuggest('".$ingredientSuggest."', this.id);\" autocomplete=\"off\"/>
<input type=\"text\" name=\"amount\" />
<input type=\"text\" name=\"volume\" />
<input type=\"button\" value=\"Remove\" onclick=\"this.parentNode.parentNode.removeChild(this.parentNode);\" />
</div>
and the two way of calling:
Automatically: <input type="text" name="amount" onChange="javascript:moreFields(); " />
Bu this button: <input type="button" id="moreFields" value="Give me more fields!" />
Anybody has a keen eye and spots the problem?
Thanks so much!
J.