Take a closer look at the document descalzo linked to. Setting some attributes on form input elements using setAttribute won't work in IE. Instead, use the attribute-mapped JS properties:
Code:
element.type = 'hidden';
element.name = 'foo';
This is part of the larger problem IE has with dynamically created and altering form elements, namely that it doesn't handle them properly. In particular, if you dynamically add an element to a form, you can't access it by name. Fortunately, you can add the element by name yourself (see code at end of post).
The if statements in the "Create Base Amount" and "Create Base Description" sections are redundant; if either corresponding element isn't in the form, the parent block will be skipped.

Originally Posted by
driveflexfuel
Code:
if(frmName.amount != null && frmName.item_name != null){
...
//Create Base Amount
if(frmName.amount != null){
...
}
//Create Base Description
if(frmName.item_name != null){
...
}
You could reuse the variable that holds the newly created elements rather than having separate elementN variables, except that you should instead refactor the repeated code to create inputs into a function.
Code:
function create_input(form, name, value) {
var input = document.createElement("input");
// unnecessary; 'text' is the default
//input.type = 'text';
input.name = name;
input.value = value;
form.appendChild(input);
if (!form.elements[name]) {
// handle IE bug where dynamically added form inputs
// can't be referenced by name
form.elements[name] = input;
}
}
function create_page(){
var frm_count = document.forms.length;
dbgMsg('forms.length: ' + frm_count);
for (var i=0, ppFormCnt=1; i<=frm_count-1; ++i){
var form = document.forms[i];
dbgMsg('form'+i);
if(form.amount != null && form.item_name != null){
dbgMsg('entered form creation');
form.name = 'pp_form' + ppFormCnt++;
form.onsubmit = function() {
report('submitting '+this.name);
this.target = 'paypal';
return ReadForm(this);
};
//Create Multi value if needed
if(form.multi == null){
create_input(form, 'multi', 0);
}
//Create Base Amount
create_input(form, 'baseamt', form.amount.value);
//Create Base Description
create_input(form, 'basedes', form.item_name.value);
}
}
}
Note that you should refer to the dynamically added form elements by form.elements.name rather than form.name.
Alternatively,
Code:
function create_input(form, attrs) {
var input = document.createElement("input");
for (p in attrs) {
input[p] = attrs[p];
}
form.appendChild(input);
if (! form.elements[attrs.name]) {
form.elements[attrs.name] = input;
}
}
...
//Create Multi value if needed
if(form.multi == null){
create_input(form, {name: 'multi', value: 0, type: 'hidden'});
}
//Create Base Amount
create_input(form, {name: 'baseamt',
value: form.amount.value,
type: 'hidden'});
//Create Base Description
create_input(form, {name: 'basedes',
value: form.item_name.value,
type: 'hidden'});