setting form values via external js file ... trying to use document.form.filed.value

Discussion in 'Javascript' started by jason@cyberpine.com, Nov 7, 2004.

  1. Guest

    I have a function that <body onload=..> sets some form values. However
    when i execute that functionf from external js file, i get erorrs and
    it dont work.

    The function sets the fields via

    document.forname.fieldname.value = xx;

    I would imagine document no longer applies since external js file. How
    can i do this from an external js file.

    thanks.
    , Nov 7, 2004
    #1
    1. Advertising

  2. On 7 Nov 2004 08:27:23 -0800, <> wrote:

    [snip]

    > document.forname.fieldname.value = xx;
    >
    > I would imagine document no longer applies since external js file.


    Not at all. The script will act exactly as it would had you pasted the
    contents within a SCRIPT element.

    > How can i do this from an external js file.


    As you normally might.

    Could you show an example, preferably presenting a small demonstration
    somewhere on the Web.

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Nov 7, 2004
    #2
    1. Advertising

  3. Guest

    Thanks for response.

    I found my bug. I had left the <script language> tag in the .js file
    .... and apparently you can't have html in an external js file so the
    function was not being found.

    Incidently, what's the best way to expand on these javascript errors
    you might get at the bottom of the browser screen. Any way to get more
    detail, and maybe a line number or something. I'm using IE 6.0.

    Thanks.
    , Nov 8, 2004
    #3
  4. On 8 Nov 2004 05:45:04 -0800, <> wrote:

    > Thanks for response.


    You're welcome.

    > I found my bug. I had left the <script language> tag [...]


    The language attribute is deprecated, by the way. It has been for over six
    years. The script type should be specified using the type attribute:

    <script type="text/javascript">

    > ... and apparently you can't have html in an external js file so the
    > function was not being found.


    No, you certainly can't. The external file should only contain content
    that is valid for the script language.

    > Incidently, what's the best way to expand on these javascript errors you
    > might get at the bottom of the browser screen. Any way to get more
    > detail, and maybe a line number or something. I'm using IE 6.0.


    You can add the Microsoft Script Debugger, but I found it cumbersome to
    use. I would recommend using another browser, which is generally a good
    idea for Web development anyway as you don't fall into the trap of using
    Microsoft-only "features"[1].

    Opera's Javascript console automatically includes a trace through your
    script that's very useful in determining what went wrong, where. The
    development tools that come with the Mozilla Browser Suite and Mozilla
    Firefox are also better than the IE console.

    Opera <URL:http://www.opera.com/>
    Mozilla <URL:http://www.mozilla.org/>

    Mike


    [1] Unless you're developing for a Microsoft-only environment, of course.

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Nov 8, 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. null hypothesis
    Replies:
    1
    Views:
    282
    Eric Sosman
    Sep 6, 2010
  2. Tradeorganizer
    Replies:
    3
    Views:
    144
    Tradeorganizer
    Feb 7, 2007
  3. Jorntk

    dynamic generate form filed

    Jorntk, Apr 23, 2004, in forum: Javascript
    Replies:
    2
    Views:
    75
    Grant Wagner
    Apr 23, 2004
  4. Replies:
    2
    Views:
    289
  5. dan_matthew

    Setting form values with external .js file

    dan_matthew, Sep 30, 2005, in forum: Javascript
    Replies:
    2
    Views:
    181
    dan_matthew
    Sep 30, 2005
Loading...

Share This Page