In a form loaded vian an ajax call, I am trying to reference an element in the form.
I've gone as simple as an onClick activated alert box to display a value within the form and am receiving errors stating what I am referencing is null or not an object.
I have tried the following and recceived the same error every time:
this.form
document.form
document.addSubConsultant
dcoument.getElementById('addSubConsultant')
this.addSubConsultant.
The code from within this ajax called script is as follows:
$display = "{$args}<form name=\"addSubConsultant\" id=\"addSubConsultant\">\n";
$display .= "<table width=\"400\" cellspacing=1 class=\"subtable\" style=\"border: solid 1px #c2c3cf\">\n";
$display .= " <tr>\n";
$display .= " <td><b>Contract</b></td>\n";
$display .= " <td><b>Phase</b></td>\n";
$display .= " <td><b>Amount</b></td>\n";
$display .= " </tr>\n";
if ($addrow == 'true'){
$currentRowCount++;
}
for ($i=0; $i<$currentRowCount; $i++){
$display .= " <tr>\n";
$display .= " <td align=\"right\">" . $this->main->form->inputbox("sub_consultant_contract[]", "", 20, "text") . "</td>\n";
$display .= " <td align=\"right\">" . $this->main->form->inputbox("sub_consultant_phase[]", "", 20, "text") . "</td>\n";
$display .= " <td align=\"right\">" . $this->main->form->inputbox("sub_consultant_amount[]", "", 20, "text") . "</td>\n";
if ($i == ($currentRowCount - 1)){
$display .= " <td align=\"right\"><a href=\"javascript:;\" OnClick=\"alert(document.addSubConsultant.sub_consultant_contract[0].value);\" title=\"Add another\" alt=\"Add another\"><span style=\"font-size:20px; font-weight: bold; color: #00FF0B;\">+</span></a></td>\n"; //get_SubConsultantsForm({$currentRowCount},'true',this.form);
}
$display .= " </tr>\n";
}
$display .= " <tr>\n";
$display .= " <td valign=\"top\"></td>\n";
$display .= " <td align=\"right\">" . $this->main->form->button("submitproject", "Submit", "onClick=\"submitSubConsultantsForm(document.cnpform.codelist.value);\"") . " " . $this->main->form->button("cancelloc", "Cancel", "onClick=\"cancellookup('project');\"") . "</td>\n";
$display .= " </tr>\n";
$display .= "</table>\n";
$display .= "</form>\n";
return $this->main->ajax->xml_format("<field><![CDATA[{$display}]]></field>");
The form name is 'addSubConsultant'
The line I am working with is this one:
$display .= " <td align=\"right\"><a href=\"javascript:;\" OnClick=\"alert(document.addSubConsultant.sub_consultant_contract[0].value);\" title=\"Add another\" alt=\"Add another\"><span style=\"font-size:20px; font-weight: bold; color: #00FF0B;\">+</span></a></td>\n";
The error I recieve is this one:
Error: 'document.addSubContractor.sub_consultant_contract.0' is null or not an object.
Where am I going wrong here?
Thanks