Web Analytics Made Easy -
StatCounter Fieldset JS problem - CodingForum

Announcement

Collapse
No announcement yet.

Fieldset JS problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fieldset JS problem

    Hi,

    I've got a <fieldset> written in part of my JSP page. The HTML code looks fine. However, when looping through all the elements of the form in which it's contained, it returns an undefined error and bombs out the rest of the script.

    The actual JS is fine. So, too is the HTML. Or so it seems anyway.

    Is there any reason for this to be the case?

    This is the HTML:
    ------------------------------------------------------------
    <fieldset name="fileslist" id="fileslist">
    <legend><fmt:message key="files_dlg.msg.title" /></legend>
    <c:if test="${sessionScope.SESSION_ATTACHMENTS != null}">
    <ul>
    <c:forEach items="${sessionScope.SESSION_ATTACHMENTS}" var="attachedFile">
    <li><cut value="${attachedFile}"/></li>
    </c:forEach>
    </ul>
    </c:if>

    <c:if test="${sessionScope.SESSION_ATTACHMENTS == null}">
    <h4><fmt:message key="files_dlg.msg.nofiles" /></h4>
    </c:if>
    </fieldset>
    ------------------------------------------------------------

    The JS is fine. It just iterates through all the forms and then each element in the form.

    hmmmm .... what's going on?
    *keep it simple (TM)

  • #2
    Seeing the HTML ouptut would be alot more helpful than your CF source markup.

    Only thing I can add at the moment is the fieldsets are part of a form's elements collection.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

    Comment


    • #3
      Your question was also answered here.

      .....Willy

      Comment


      • #4
        hi, beetle, thanks for the advice.

        however, like i said, the html is fine. voila output:

        -----------------------------------------
        <fieldset name="fileslist" id="fileslist">
        <legend>Attached Files:</legend>
        <h3>You currently have no files uploaded to the server during this session</h3>
        </fieldset>
        ------------------------------------------

        the problem seems to be, that even tho the fieldset is part of the files collection and that my JS function picks it up, it seems to think the element type is undefined.

        it's weird.
        *keep it simple (TM)

        Comment


        • #5
          Well, then maybe we should have a look at that JS then.
          My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
          “Minds are like parachutes. They don't work unless they are open”
          “Maturity is simply knowing when to not be immature”

          Comment


          • #6
            willy: that's coz I'm scotbot on that forum. used to be scotbot on here too, till i forgot my password and can't get in to change my email address. grrrrr ...

            however, if you read my point, it is a JS issue - not Java or JSP or JSTL HTML. JS seems unable to resolve my markup that's all.
            *keep it simple (TM)

            Comment


            • #7
              again, beetle, nothing wrong with the JS. all other form elements return the appropriate type.

              but why not the fieldset? that is what I initially asked, after all.
              *keep it simple (TM)

              Comment


              • #8
                Okay - you maintain that everything is fine, yet you posted here because you're getting an error. So, which is it?

                I can't pull answers out from the dark, you know.
                My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
                “Minds are like parachutes. They don't work unless they are open”
                “Maturity is simply knowing when to not be immature”

                Comment


                • #9
                  JS:
                  ------------------------------------

                  function disablesubmit(forma)
                  {
                  for (var i=0; i < document.forms.length; i++)
                  {
                  objFrm = document.forms[i] ;

                  for (var j=0; j < objFrm.elements.length; j++)
                  {
                  objElm = objFrm.elements[j];


                  alert(objElm.name +":\t"+ objElm.type) ;
                  if (objElm.type.toLowerCase()=='button' || objElm.type.toLowerCase()=='submit' || objElm.type.toLowerCase()=='image') objElm.disabled = true;
                  }
                  }

                  return;
                  }
                  ---------------------------------------------------------------
                  *keep it simple (TM)

                  Comment


                  • #10
                    Okay, your JS is not fine. Here's the proper way to test for an undefined value
                    Code:
                    if ( typeof objElm.type == 'undefined' )
                    typeof is a unary operator -- details here
                    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
                    “Minds are like parachutes. They don't work unless they are open”
                    “Maturity is simply knowing when to not be immature”

                    Comment


                    • #11
                      beetle, we're getting crossed wires here.

                      I wasn't testing for an "undefined" error. I was getting an undefined error when trying to run the above script. the alert has been put in to test which element was being called undefined.

                      as it turned out, the fieldset was throwing this error. but that's not wot I wanted know.

                      i wanted to know why would this be the case when a fieldset is part of the forms collection. surely, it shouldn't be undefined if it's a part of the collection i'm iterating through. it makes no sense, otherwise!
                      *keep it simple (TM)

                      Comment


                      • #12
                        Originally posted by jbot
                        I wasn't testing for an "undefined" error. I was getting an undefined error when trying to run the above script. the alert has been put in to test which element was being called undefined.
                        Well, then you should be. type isn't an exposed property for fieldset elements.

                        So, it's not the fieldset itself that is undefined, but rather, the type property of it.
                        My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
                        “Minds are like parachutes. They don't work unless they are open”
                        “Maturity is simply knowing when to not be immature”

                        Comment


                        • #13
                          thanks, beetle, in light of that it all makes sense.

                          but then, that's all what i wanted to know: the reason why it wouldn't work, not the extra stuff.

                          cheers all the same.
                          *keep it simple (TM)

                          Comment


                          • #14
                            But I never woud have reached that conclusion without seeing your code. I could have guessed, but honestly, I don't have time for guessing.

                            Oh, and you're quite welcome.
                            My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
                            “Minds are like parachutes. They don't work unless they are open”
                            “Maturity is simply knowing when to not be immature”

                            Comment

                            Working...
                            X