Very Simple JavaScript Question

Discussion in 'HTML' started by Roy Schestowitz, Jan 7, 2005.

  1. Let us say I have a JavaScript function called get_one() which returns a
    one. I am not entirely sure if the returned value can be accessed only by
    another function. Is there a way of doing something like the following?

    <font size=get_one()>Hello World</font>

    Must I use document.write?

    Thanks and sorry about the low level of this question,
    Roy
    Roy Schestowitz, Jan 7, 2005
    #1
    1. Advertising

  2. In article <crlb86$2rqp$>,
    says...
    > Let us say I have a JavaScript function called get_one() which returns a
    > one. I am not entirely sure if the returned value can be accessed only by
    > another function.


    The value returned can be accessed by any other function or operation as
    long as it's within scope.


    > Is there a way of doing something like the following?
    >
    > <font size=get_one()>Hello World</font>
    >
    > Must I use document.write?


    Yes, though which version of HTML are you using? Presumably it's an old
    one, seeing as you've got a <font> element.

    --
    Hywel http://kibo.org.uk/
    I do not eat quiche.
    Hywel Jenkins, Jan 7, 2005
    #2
    1. Advertising

  3. Hywel Jenkins wrote:

    > In article <crlb86$2rqp$>,
    > says...
    >> Let us say I have a JavaScript function called get_one() which returns a
    >> one. I am not entirely sure if the returned value can be accessed only by
    >> another function.

    >
    > The value returned can be accessed by any other function or operation as
    > long as it's within scope.



    That's what I imagined. I need to fetch a URL for an image. Does it mean I
    have to write a block, assign it an ID and then overwrite it with
    document.write? I have done this with <div> before but what if I have a
    very large <table>...</table> block?


    > ...though which version of HTML are you using? Presumably it's an old
    > one, seeing as you've got a <font> element.



    I simplified a much larger problem. I don't use <font>

    Thanks,
    Roy

    --
    Roy Schestowitz
    http://schestowitz.com
    Roy Schestowitz, Jan 7, 2005
    #3
  4. Hywel Jenkins wrote:

    > In article <crlb86$2rqp$>,
    > says...
    >> Let us say I have a JavaScript function called get_one() which returns a
    >> one. I am not entirely sure if the returned value can be accessed only by
    >> another function.

    >
    > The value returned can be accessed by any other function or operation as
    > long as it's within scope.
    >
    >
    >> Is there a way of doing something like the following?
    >>
    >> <font size=get_one()>Hello World</font>
    >>
    >> Must I use document.write?

    >
    > Yes, though which version of HTML are you using? Presumably it's an old
    > one, seeing as you've got a <font> element.


    My problem is now a little different. If I use document.write to write HTML
    that has JavaScript within it, the JavaScript does not work. Is there a way
    around this?

    --
    Roy Schestowitz
    http://schestowitz.com
    Roy Schestowitz, Jan 7, 2005
    #4
  5. Roy Schestowitz

    Toby Inkster Guest

    Roy Schestowitz wrote:

    > Let us say I have a JavaScript function called get_one() which returns a
    > one. I am not entirely sure if the returned value can be accessed only by
    > another function. Is there a way of doing something like the following?
    >
    > <font size=get_one()>Hello World</font>


    <body onload="document.getElementById('foo').size=get_one();">
    <font id="foo">Hello World</font>
    </body>

    ??

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Jan 7, 2005
    #5
  6. Roy Schestowitz

    SpaceGirl Guest

    Toby Inkster wrote:
    > Roy Schestowitz wrote:
    >
    >
    >>Let us say I have a JavaScript function called get_one() which returns a
    >>one. I am not entirely sure if the returned value can be accessed only by
    >>another function. Is there a way of doing something like the following?
    >>
    >><font size=get_one()>Hello World</font>

    >
    >
    > <body onload="document.getElementById('foo').size=get_one();">
    > <font id="foo">Hello World</font>
    > </body>
    >
    > ??
    >


    Maybe...:

    <script type="text/javascript>
    function get_one() {
    x = 1;
    return x;
    }
    </script>

    <body onload="document.getElementById('foo').style.fontsize=get_one();">
    <div id="foo">Hello World</div>
    </body>


    --


    x theSpaceGirl (miranda)

    # lead designer @ http://www.dhnewmedia.com #
    # remove NO SPAM to email, or use form on website #
    SpaceGirl, Jan 7, 2005
    #6
  7. SpaceGirl wrote:

    > Toby Inkster wrote:
    >> Roy Schestowitz wrote:
    >>
    >>
    >>>Let us say I have a JavaScript function called get_one() which returns a
    >>>one. I am not entirely sure if the returned value can be accessed only by
    >>>another function. Is there a way of doing something like the following?
    >>>
    >>><font size=get_one()>Hello World</font>

    >>
    >>
    >> <body onload="document.getElementById('foo').size=get_one();">
    >> <font id="foo">Hello World</font>
    >> </body>
    >>
    >> ??
    >>

    >
    > Maybe...:
    >
    > <script type="text/javascript>
    > function get_one() {
    > x = 1;
    > return x;
    > }
    > </script>
    >
    > <body onload="document.getElementById('foo').style.fontsize=get_one();">
    > <div id="foo">Hello World</div>
    > </body>


    Thanks guys!

    I have already done this in PHP (had to learn it as well to get it done)
    because I imagined it would be impossible with _simple_ JavaScript.

    Took longer, but at least I learned something new...


    Roy

    --
    Roy Schestowitz
    http://schestowitz.com
    Roy Schestowitz, Jan 7, 2005
    #7
  8. Roy Schestowitz <> wrote:

    > My problem is now a little different. If I use document.write to
    > write HTML that has JavaScript within it, the JavaScript does not
    > work. Is there a way around this?


    Maybe, but it sounds like you're trying to solve something in a wrong
    way. What are you trying to do in the first place?

    --
    David Håsäther
    David Håsäther, Jan 7, 2005
    #8
  9. On Fri, 07 Jan 2005 10:36:23 +0000, SpaceGirl
    <> wrote:

    [snip]

    > Maybe...:


    Getting there... :D

    > <script type="text/javascript>

    ^
    Forgot the closing quote.

    > function get_one() {
    > x = 1;


    This would create a global variable, x, when I doubt that's required (nor
    desired). Always use the var keyword.

    > return x;


    I'd have thought

    return 1;

    would be simpler.

    > }


    > [...].style.fontsize=get_one();">


    The 's' in fontsize must be capitalised.

    Finally, '1' wouldn't be a valid value to be assigned to the fontSize
    property; you still have to follow the CSS specification and include units
    for length values (or use one of the other accepted value types).

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Jan 7, 2005
    #9
  10. Roy Schestowitz

    SpaceGirl Guest

    Michael Winter wrote:
    > On Fri, 07 Jan 2005 10:36:23 +0000, SpaceGirl
    > <> wrote:
    >
    > [snip]
    >
    >> Maybe...:

    >
    >
    > Getting there... :D
    >
    >> <script type="text/javascript>

    >
    > ^
    > Forgot the closing quote.
    >
    >> function get_one() {
    >> x = 1;

    >
    >
    > This would create a global variable, x, when I doubt that's required
    > (nor desired). Always use the var keyword.
    >
    >> return x;

    >
    >
    > I'd have thought
    >
    > return 1;
    >
    > would be simpler.
    >
    >> }

    >
    >
    >> [...].style.fontsize=get_one();">

    >
    >
    > The 's' in fontsize must be capitalised.
    >
    > Finally, '1' wouldn't be a valid value to be assigned to the fontSize
    > property; you still have to follow the CSS specification and include
    > units for length values (or use one of the other accepted value types).
    >
    > Mike
    >


    meh. :pppppppppppp

    --


    x theSpaceGirl (miranda)

    # lead designer @ http://www.dhnewmedia.com #
    # remove NO SPAM to email, or use form on website #
    SpaceGirl, Jan 7, 2005
    #10
  11. Roy Schestowitz

    Toby Inkster Guest

    Michael Winter wrote:

    > Finally, '1' wouldn't be a valid value to be assigned to the fontSize
    > property; you still have to follow the CSS specification and include units
    > for length values (or use one of the other accepted value types).


    Yes -- which is why I used document.getElementById('foo').size instead of
    going into the "style" object, as I didn't want to modify the get_one
    function.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Jan 7, 2005
    #11
  12. On Fri, 07 Jan 2005 22:18:41 +0000, Toby Inkster
    <> wrote:

    > Michael Winter wrote:
    >
    >> Finally, '1' wouldn't be a valid value to be assigned to the fontSize
    >> property [...]

    >
    > Yes -- which is why I used document.getElementById('foo').size instead
    > of going into the "style" object, as I didn't want to modify the get_one
    > function.


    But as the OP revealed in another part of this thread, he isn't using a
    FONT element so the size property doesn't apply. :) Though 1 is unlikely
    to be the value assigned in the OP's real code, I thought I should just
    point out the applicable limitations.

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Jan 7, 2005
    #12
  13. David Håsäther wrote:

    > Roy Schestowitz <> wrote:
    >
    >> My problem is now a little different. If I use document.write to
    >> write HTML that has JavaScript within it, the JavaScript does not
    >> work. Is there a way around this?

    >
    > Maybe, but it sounds like you're trying to solve something in a wrong
    > way. What are you trying to do in the first place?


    It's all done now. I did it in both JavaScript and PHP (separate version for
    each). I started with PHP, but I then realised it's too hard to get local
    time so I re-implemented this in JavaScript (with your kind help).

    Thanks everyone. It's in the very front page below if anyone wants to have a
    peek.

    --
    Roy Schestowitz
    http://schestowitz.com
    Roy Schestowitz, Jan 8, 2005
    #13
    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. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    473
    Raymond Hettinger
    Jul 27, 2003
  2. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,616
    Merrill & Michele
    Oct 19, 2004
  3. Abhishek Jha

    very very very long integer

    Abhishek Jha, Oct 16, 2004, in forum: C Programming
    Replies:
    4
    Views:
    419
    jacob navia
    Oct 17, 2004
  4. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    513
    Dave Thompson
    Feb 14, 2005
  5. olivier.melcher

    Help running a very very very simple code

    olivier.melcher, May 12, 2008, in forum: Java
    Replies:
    8
    Views:
    2,288
Loading...

Share This Page