Append parent name to the correct field

Hello,

I’m trying to create a form that will append the parent’s first and last name in the correct field, which is the ddepartment field. I must be missing something or doing it wrong because it is not appending to the ddepartment field. Your help is much appreciated as I’m lost.

JavaScript:

 //parent or guardian name// 
    var field = document.createElement("input");
    	field.name = "ddepartment";
    	field.type = "hidden";
    	field.value = "parentLast" + "," + "parentFirst";
            form.appendChild(field);

part of the form:

<tr>
        <td><span class="formHelpNote"></span>First Name:</span></td>
        <td colspan="2">
        <span class="formHelpNote"><input name="parentFirst" value="" size="20" maxlength="40" onkeydown="return blockEnter(event)" onkeyup="return cUpper(this)">
        </span>
        </td>
        </tr>
        <tr>
        <td><span class="formHelpNote"></span>Last Name:</td>
        <td colspan="2">
        <span class="formHelpNote"><input name="parentLast" value="" size="40" maxlength="60" onkeydown="return blockEnter(event)" onkeyup="return cUpper(this)"></span>
        </td>

I think its because ‘form’ isn’t defined anywhere in your code.

e.g. Find the element you want to append to.

 var form = document.getElementById("form");

Assumes html like this:

<form id="form"> etc..

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.