I have a javascript form I am creating inside an innerHTML element of a Div tag.
However, when I loop through to get the elements, it gives me the following error:
document.send_samples_form
is undefined
However, I can call the form elements inside using Firebug as well as see the Form using Firebug.
I am assuming I might have to use an alternative method of writing to the innerHTML (possibly using the DOM) however, I am not sure how to go about doing this. I would much rather just make this javascript work with innerHTML if possible. Could anyone provide some help?
Thanks!
Here is the javascript code that is creating the form:
document.getElementById('s
amples_to_
send_div')
.innerHTML
= '<form name="send_samples_form" id="send_samples_form"><fi
eldset><le
gend>Sendi
ng Sample(s) to ' + name + '</legend>' + data + '<br><input id="send_transfer" type="button" class="button" value="Send Transfer" onclick="sendSamplesToAcco
untsContac
ts(\'' + id + '\', \'' + samples_id + '\', \'' + type + '\')"> <input type="button" class="button" value="Cancel" onclick="showAccountsConta
ctsGrid(\'
accounts\'
);"></fiel
dset></for
m>';
And here is the javascript that is looping through the form elements:
for(i=0; i < document.send_samples_form
.elements.
length; i++)
{
if(document.send_samples_f
orm.elemen
ts[i].id.s
ubstr(0,4)
== 'qty_') {
qty = parseInt(document.send_sam
ples_form.
elements[i
].value);
//alert(document.send_samp
les_form.e
lements[i]
.id.substr
(5));
$j.post("pharma_SendSample
s.php", { id: id, samples_id: samples_id, type: type, qty: qty });
}
} // end for loop
Thanks!
Start Free Trial