Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Well, just for starters, named <form>s *ARE* obsolete.

    Which means that the the construction document.siteForm is also obsolete.

    I don't know of any browser that actually enforces this--all that I have used still support document.siteForm--but possibly you have run into a browser that is enforcing the obsolescence?

    In short, I wouldn't worry too much about it because document.getElementById('siteForm') is the correct modern coding. And kill the name= in your <form> tag.

    *******

    Possible reason: Although IDs must be unique on a page, names do not need to be unique, at all. However, if you have multiple objects with the same name, then JS will treat them as an array.

    Perhaps you have *another* object on the page with that same name?

    An easy way to find out:
    Code:
    alert( document.siteForm.length );
    That will be null if there is only one name "siteForm" or will tell you how many there are if more than one.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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