document.write within a form

Discussion in 'Javascript' started by cerr, Feb 15, 2012.

  1. cerr

    cerr Guest

    Hi,

    I would like to passalong two parameters as hidden fields within a
    form thus I did following:
    <script type="text/javascript">
    alert("screensize: "+screen.availHeight + "x" +
    screen.availWidth);
    dodcument.write("<input type=\"hidden\" name=\"height\" value=
    \""+screen.availHeight+"\"/>");
    dodcument.write("<input type=\"hidden\" name=\"width\" value=
    \""+screen.availWidth+"\"/>");
    </script>
    within the form but that doesn't seem to work, why not I'm wondering,
    any hints or suggestion?
    Help would be appreciated!

    Thank you very much!
    Ron
     
    cerr, Feb 15, 2012
    #1
    1. Advertisements

  2. 2012-02-15 8:29, cerr wrote:

    > I would like to passalong two parameters as hidden fields within a
    > form thus I did following:
    > <script type="text/javascript">
    > alert("screensize: "+screen.availHeight + "x" +
    > screen.availWidth);
    > dodcument.write("<input type=\"hidden\" name=\"height\" value=
    > \""+screen.availHeight+"\"/>");
    > dodcument.write("<input type=\"hidden\" name=\"width\" value=
    > \""+screen.availWidth+"\"/>");
    > </script>
    > within the form but that doesn't seem to work, why not I'm wondering,


    Well, you didn't lint your code, did you? Which object might "dodcument" be?

    But the main point is that you shouldn't try to use document.write() for
    such purposes. Instead, add elements to the document tree in a
    structured manner. If you don't know how to do that, you shouldn't be
    messing around with document modifications before you've read a
    JavaScript tutorial.

    Or maybe the main point is really that you are trying to do the wrong
    thing, getting screen size and passing the information to a server.
    Unless you are trying to collect statistics, it's difficult to see what
    useful purpose it might serve (and not so difficult to guess what wrong
    ideas one might try to implement that way).

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Feb 15, 2012
    #2
    1. Advertisements

  3. cerr

    cerr Guest

    On Feb 14, 11:18 pm, "Jukka K. Korpela" <> wrote:
    > 2012-02-15 8:29,cerrwrote:
    > > I would like to passalong two parameters as hidden fields within a
    > > form thus I did following:
    > >                    <script type="text/javascript">
    > >                    alert("screensize: "+screen.availHeight + "x" +
    > > screen.availWidth);
    > >                          dodcument.write("<input type=\"hidden\" name=\"height\" value=
    > > \""+screen.availHeight+"\"/>");
    > >                          dodcument.write("<input type=\"hidden\" name=\"width\" value=
    > > \""+screen.availWidth+"\"/>");
    > >                    </script>
    > > within the form but that doesn't seem to work, why not I'm wondering,

    >
    > Well, you didn't lint your code, did you? Which object might "dodcument" be?
    >
    > But the main point is that you shouldn't try to usedocument.write() for
    > such purposes. Instead, add elements to the document tree in a
    > structured manner. If you don't know how to do that, you shouldn't be
    > messing around with document modifications before you've read a
    > JavaScript tutorial.
    >
    > Or maybe the main point is really that you are trying to do the wrong
    > thing, getting screen size and passing the information to a server.
    > Unless you are trying to collect statistics, it's difficult to see what
    > useful purpose it might serve (and not so difficult to guess what wrong
    > ideas one might try to implement that way).
    >

    Hi Jukka,

    Thanks for getting back - Wel I ultimately would like to adjust the
    size of a google map depending on the screensize cause the way i have
    it right now, it looks decent ona desktop screen but doesn't looks so
    good on my tablet e.g.... I thought I could pass the measures around
    to my script in the next page that prints out the html conmtaining the
    Google map and just adjust the image size appropriately... any better
    methods of doing that?

    Thanks,
    Ron
     
    cerr, Feb 15, 2012
    #3
    1. Advertisements

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. Tony Prichard
    Replies:
    0
    Views:
    1,066
    Tony Prichard
    Dec 12, 2003
  2. Manish Hatwalne
    Replies:
    1
    Views:
    641
    Martin Honnen
    Jul 13, 2004
  3. Replies:
    4
    Views:
    1,040
  4. Chuck Amadi
    Replies:
    0
    Views:
    699
    Chuck Amadi
    Jun 22, 2004
  5. Mike Daniel
    Replies:
    5
    Views:
    608
    Dr John Stockton
    Sep 15, 2003
  6. Ignac Vucko
    Replies:
    7
    Views:
    410
    Michael Winter
    Mar 11, 2005
  7. jullag
    Replies:
    20
    Views:
    667
    Frances
    Sep 22, 2005
  8. Frank Peterson
    Replies:
    9
    Views:
    505
    David Mark
    Jun 28, 2009
Loading...