Avatar of swhitlow
swhitlow

asked on 

Accessing Form Elements & innerHTML problems

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('samples_to_send_div').innerHTML = '<form name="send_samples_form" id="send_samples_form"><fieldset><legend>Sending Sample(s) to ' + name + '</legend>' + data + '<br><input id="send_transfer" type="button" class="button" value="Send Transfer" onclick="sendSamplesToAccountsContacts(\'' + id + '\', \'' + samples_id + '\', \'' + type + '\')"> &nbsp;&nbsp;<input type="button" class="button" value="Cancel" onclick="showAccountsContactsGrid(\'accounts\');"></fieldset></form>';


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_form.elements[i].id.substr(0,4) == 'qty_') {
                  qty = parseInt(document.send_samples_form.elements[i].value);
                  //alert(document.send_samples_form.elements[i].id.substr(5));
                  $j.post("pharma_SendSamples.php", { id: id, samples_id: samples_id, type: type, qty: qty });
            }
      } // end for loop


Thanks!
JavaScript

Avatar of undefined
Last Comment
swhitlow

8/22/2022 - Mon