www.webdeveloper.com
Results 1 to 2 of 2

Thread: Not getting the form

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    113

    Question Not getting the form

    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
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    The code you posted works - it shows a blank alert which is correct.

    document.siteForm addresses the form via the name attribute only.

    This works but is deprecated and should not be used. Then name attribute should only be applied the the elements of forms, not the <form> tag.

    document.getElementById('siteForm') is correct syntax for addressing an element by its ID.

    If you apply an onclick handler to a form element (not a link within the form),
    the handler can reference other elements directly by name (not ID), or via this.form.elementName








Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles