SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot maileen's Avatar
    Join Date
    Apr 2006
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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:
    Code:
    <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:
    Code:
    document.getElementById('siteForm').boxchecked.value
    instead of:
    Code:
    document.siteForm.boxchecked.value
    why ?
    it's like js is not able to find the siteForm form object

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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.

    Code javascript:
    document.forms['siteForm'].boxchecked.value


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •