Null or not an object - Not displaying document.write(...) in child modal window .

Discussion in 'Javascript' started by Gretjns, Oct 6, 2004.

  1. Gretjns

    Gretjns Guest

    I'm trying to figure out this script doesn't display any text in the
    child window and why I'm getting the null or not an object error.
    It's taken directly from the Javascript and DHTML cookbook (not listed
    in the book errata on o'reilly website). Initially I get an error
    "window.dialogArguments.yourName" is null or not an object. Then I
    fill out the field on the form, press the button and the child window
    does display but there is no text inside the child window.

    Questions: Should I be declaring an object that isn't currently
    declared like "window"? or is "window" a built in object that doesn't
    need declaring? do I need to assign the dialogDoc.html or "result" to
    "document" somehow? It looks like they have me putting a value in
    "result" then never actually using "result"... confused... Using ie
    6.02800...Suggestions? gj


    <html>
    <head>
    <title> Launch a Modal Dialog</title>
    <script type="text/javascript">

    function openDialog(form){
    var result = window.showModalDialog("dialogDoc.html", form,
    "dialogWidth:300px; dialogHeight:201px; center:yes");
    }
    </script>
    </head>
    <body>
    <h1>Internet Explorer Modal Dialog Window</h1>
    <hr />
    <form name="sample" action="#" onsubmit="return false">
    Enter your name for the dialog box:<input name="yourName" type="text"
    />
    <input type="button" value="Send to Dialog"
    onclick="openDialog(this.form)" />
    </form>
    </body>
    </html>

    <html>
    <head>
    <title>Modal Dialog</title>
    </head>
    <body>
    <script type="text/javascript">
    document.write("Greetings from " +
    window.dialogArguments.yourName.value + "!");
    </script>
    </body>
    </html>
     
    Gretjns, Oct 6, 2004
    #1
    1. Advertising

  2. Gretjns

    Jc Guest

    The "this.form" on the onclick event of the button looks kind of
    out-of-place to me, I typically use a different way to reference
    objects. Here's something else to try instead of "this.form":

    document.forms("sample")

    Here's a reference for the above code:

    http://msdn.microsoft.com/library/d...hor/dhtml/reference/dhtml_reference_entry.asp

    Click the reference link at the top of the page to see the full DHTML
    Reference.
     
    Jc, Oct 7, 2004
    #2
    1. Advertising

  3. On 6 Oct 2004 20:44:46 -0700, Jc <> wrote:

    > The "this.form" on the onclick event of the button looks kind of
    > out-of-place to me, I typically use a different way to reference
    > objects. [...]


    In intrinsic events, the this operator refers to the element. So with

    <input ... onchange="this....">

    the object reference yielded by the this operator refers to that INPUT
    element. Furthermore, all form controls contain a property, form, which
    refers to the containing form, if one exists.

    > document.forms("sample")


    You should use square brackets to subscript collections. The use of
    parentheses appears to be a Microsoft invention that isn't supported by
    all browsers. It certainly fails in the Mozilla Suite and Firefox.

    document.forms['formName']

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Oct 7, 2004
    #3
  4. Jc wrote:
    > The "this.form" on the onclick event of the button looks kind of
    > out-of-place to me,


    A function assigned as the event handler for an element is executed as a
    method of that element and as a result the - this - keyword will refer
    to that element. The - form - property of form controls is a reference
    to the containing form (or null if the control is outside of the form).
    The property was implemented in the earliest browsers that implemented
    forms and has been formalised in the W3C HTML DOM standard, making -
    this.form - the most reliable (and portable) way of passing on an
    anonymous reference to the containing form from a form control event
    handler fucntion.

    > I typically use a different way to reference
    > objects. Here's something else to try instead of "this.form":
    >
    > document.forms("sample")

    <snip>

    Parenthesising "sample" turns a property accessor into a method call. It
    is a Microsoftism that, while supported by some other browsers, is not
    universally supported. It is also contrary to the W3C HTML DOM
    specification, where the ECMAScript bindings explicitly dictate the
    actions of dot/bracket notation accessors, but do not specify that the -
    forms - collection should act as a function.

    A standard bracket notation property accessor:-

    document.forms["sample"]

    - Works 100% on IE, and every other browser implementing
    -document.forms - collection. It is the cross-browser formulation to
    use in this context (the Microsoft parenthesised version should never be
    used, least it becomes a bed habit that makes cross-browser scripting
    seem harder than it really is).

    Richard.
     
    Richard Cornford, Oct 7, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bhchng
    Replies:
    0
    Views:
    664
    bhchng
    Jan 13, 2004
  2. Matt
    Replies:
    1
    Views:
    3,152
    Whitecrest
    Jun 1, 2004
  3. Matt
    Replies:
    0
    Views:
    220
  4. gopal srinivasan
    Replies:
    0
    Views:
    237
    gopal srinivasan
    Nov 5, 2004
  5. Spammay Blockay
    Replies:
    1
    Views:
    500
    Dietmar Meier
    Feb 4, 2005
Loading...

Share This Page