Not getting the form object :(

Hi,

i have a strange behavior on my webpage on my local computer.
i have 2 forms. One of them is defined as following:


<form class='form-validate view' id='siteForm' name='siteForm' method='post' action='<?php echo $url; ?>' >
   <!-- blah, blah -->
   <a class="delete" href="#" title="Delete selected records" onclick="alert(document.siteForm.boxchecked.value);">
      <span class="trash-icon"></span>
   </a>
   <!-- blah, blah -->													
   <input type="hidden" name="boxchecked" value="" />
</form>

during runtime user can tick checkboxes and a javascript function updates the value of input field called boxchecked (this works very well)

my problem:

  • if user click on the link, the alert message does not display any data… (the code on onclick is just temporary)

if i want to retrieve the value and display it correctly, i must use:


document.getElementById('siteForm').boxchecked.value

instead of:


document.siteForm.boxchecked.value

why ?
it’s like js is not able to find the siteForm form object :frowning:

The reason why your current code won’t work is because siteForm is undefined in the document object, to correctly target your form you can use the following.

document.forms['siteForm'].boxchecked.value