Ashika Umanga Umagiliya
Ashika Umanga Umagiliya

Reputation: 9158

Accessing a DIV inside a Form?

I am trying to access the DIV with the id "codeDef" using

document.getElementById['codeDef']

But it returns "undefined".What am I doing wrong here?

Here is the HTML snippet :

<div class="section">
<div class="box">
<form method="post" name="exam-company-input-form" action="./">
<table>
<tbody><tr>
<td style="width:150px;padding-left:20px">
Exam Code
</td>
<td style="width:150px;padding-left:20px"><input type="text" maxlength="10" style="width:100%" value="" name="code" onkeyup="javascript:checkExamCode();"></td><td><div id="codeDef">code def</div></td>
</tr>
<tr>

<td style="width:150px;padding-left:20px">
Orca Code
</td>
<td style="width:150px;padding-left:20px"><input type="text" maxlength="10" style="width:100%" value="" name="srycd" onkeyup="javascript:checkOrcaCode();"></td><td id="orcaDef">orca def</td>
</tr>

<tr>
<td style="text-align:center" colspan="3">
<button style="opacity: 1; margin-right: 15px;" onclick="javascript:ResetForm('exam-company-input-form');" class="blue" type="button"><span>リセット</span>
</button><button style="opacity: 1;" onclick="javascript:SubmitForm('exam-company-input-form');" class="blue" type="button"><span>登&#12288;録</span>
</button></td></tr>
</tbody></table>
<input type="hidden" value="master_exam-company-input-do" name="pid">
</form>
</div>
</div>

Upvotes: 0

Views: 1489

Answers (4)

chaitu
chaitu

Reputation: 599

it should be

   document.getElementById('codeDef');

Upvotes: 1

xdazz
xdazz

Reputation: 160833

It should be document.getElementById('codeDef').

If you use [], it means you want to get the property codeDef of the Function document.getElementId, and obviously, there is no such property, so you will get undefined.

Upvotes: 3

nbrooks
nbrooks

Reputation: 18233

document.getElementById("idName")

Use parentheses

Upvotes: 4

John Carter
John Carter

Reputation: 55271

It's a function, try

document.getElementById('codeDef')

Instead of

document.getElementById['codeDef']

Upvotes: 1

Related Questions