SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: DOM Problem

  1. #1
    SitePoint Addict
    Join Date
    Mar 2001
    Location
    the windy city
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DOM Problem

    the following gives me an error in IE6.0 and 5.5, but not in IE5.0

    I have statements like
    document.frm.realname.value
    where frm is my form's name and the error is:
    LINE:62
    ERROR: 'document.frm.realname' IS NULL OR NOT AN OBJECT.

    so what's the correct way to refer to my form fields for those browsers?

  2. #2
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its document.form.[formname].[fieldname]
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  3. #3
    SitePoint Addict
    Join Date
    Mar 2001
    Location
    the windy city
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    creole,
    thanks for such a quick response.
    for what browsers will this work?

  4. #4
    SitePoint Addict
    Join Date
    Mar 2001
    Location
    the windy city
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and one more question:
    what are the good web sites to learn about the new DOM?

  5. #5
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Arrays and objects are the same, so instead of going:

    document.formName

    You can go:

    document[frm]

    or:

    document.forms[frm]

    So, you can use either of those options. I don't think creole's will work, but it's close ;-)

    Also, you could use:

    eval("document."+frm)

    Anyway, to learn about new DOM (W3C DOM), look here:

    http://www.pageresource.com/dhtml/ryan/part4-1.html

    aDog

  6. #6
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey...I most definitely don't consider a pro at Javascript, THe only reason I posted that particular syntax is that is the syntax used in this chunk:

    <form>
    <script>
    document.write("<input type='text' name='url' size='50' value=" + window.location + ">");
    </script>

    <input type=button value="Highlight All" onClick="java script:this.form.url.focus();this.form.url.select();">
    </form>


    and that works.

    <edit>
    added don't
    </edit>
    Last edited by creole; Jul 27, 2001 at 18:32.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  7. #7
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey creole,

    I meant no offense when I said that.

    Anyway, in one, you accessing the form property of an input element (whcih returns the form that it is "in"). However:

    document.form

    Does not exist. But:

    document.forms

    Returns an array of forms contained in the document object.

    aDog

  8. #8
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Arielladog's correct.

  9. #9
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wasn't upset...I forgot to put a smiley. I also meant to put the word don't in there.

    So, how did the code sample i post work? I want to understand jscript better, but I just don't have a programmers mentality.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  10. #10
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <input type=button value="Highlight All" onClick="java script:this.form.url.focus();this.form.url.select();">
    You should take out the javascript: for one thing, because onclick is already an event handled by javascript. "javascript:" is only needed for href's.

    Onto the explanation, this refers to the current element (making it superfluous except in OOP), and each form element has a property .form which points back to the <form> tag.

    So document.yourForm.yourElement.form is the same as document.yourForm or document.forms.yourForm

  11. #11
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So my example WORKS, it's just not the easist way to do it? As long as I got it right, then I can always learn a better way to do things.

    So in the above example, if I wanted to refer to a certain field (named url) outside of the FORM tag itself, I would go:

    document.forms.url

    or ven

    document.url

    ?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  12. #12
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your example is good except for "javascript:".

    To refer to an element you'll need to give the name of the form as well:
    document.formName.url

    document.forms.url would refer to a form named url.

    You can also do: document.getElementById("url").value in IE 5+ and NS 6.

  13. #13
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by creole
    I wasn't upset...I forgot to put a smiley. I also meant to put the word don't in there.
    That makes a big difference

    Also, you could read my JavaScript OOP tutorial (here at SitePoint--both parts) and/or my DHTML/DOM one at www.pageresource.com/dhtml/ryan/ and that should help you

    What a shameless plug

    aDog

  14. #14
    SitePoint Addict
    Join Date
    Mar 2001
    Location
    the windy city
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shame on me!!!
    I solved the problem, but never updated my thread!!! (guess I was too happy - got it solved Friday afternoon andwas pretty excited it wont be bugging me over the weekend. LOL)
    It was just a plain typo. In my form tag I had name='form" instead of name="frm". Took me 2 days to pay attention to that.
    Thanks for the www.pagesourse.com link.

    Valeria


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
  •