Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Very Simple JavaScript Question

Reply
Thread Tools

Very Simple JavaScript Question

 
 
Roy Schestowitz
Guest
Posts: n/a
 
      01-07-2005
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
 
Reply With Quote
 
 
 
 
Hywel Jenkins
Guest
Posts: n/a
 
      01-07-2005
In article <crlb86$2rqp$(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed)
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.
 
Reply With Quote
 
 
 
 
Roy Schestowitz
Guest
Posts: n/a
 
      01-07-2005
Hywel Jenkins wrote:

> In article <crlb86$2rqp$(E-Mail Removed)>, (E-Mail Removed)
> 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
 
Reply With Quote
 
Roy Schestowitz
Guest
Posts: n/a
 
      01-07-2005
Hywel Jenkins wrote:

> In article <crlb86$2rqp$(E-Mail Removed)>, (E-Mail Removed)
> 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
 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      01-07-2005
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_on e();">
<font id="foo">Hello World</font>
</body>

??

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
SpaceGirl
Guest
Posts: n/a
 
      01-07-2005
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_on e();">
> <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.fonts ize=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 #
 
Reply With Quote
 
Roy Schestowitz
Guest
Posts: n/a
 
      01-07-2005
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_on e();">
>> <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.fonts ize=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
 
Reply With Quote
 
David Håsäther
Guest
Posts: n/a
 
      01-07-2005
Roy Schestowitz <(E-Mail Removed)> 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
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      01-07-2005
On Fri, 07 Jan 2005 10:36:23 +0000, SpaceGirl
<(E-Mail Removed)> wrote:

[snip]

> Maybe...:


Getting there...

> <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.
 
Reply With Quote
 
SpaceGirl
Guest
Posts: n/a
 
      01-07-2005
Michael Winter wrote:
> On Fri, 07 Jan 2005 10:36:23 +0000, SpaceGirl
> <(E-Mail Removed)> wrote:
>
> [snip]
>
>> Maybe...:

>
>
> Getting there...
>
>> <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. ppppppppppp

--


x theSpaceGirl (miranda)

# lead designer @ http://www.dhnewmedia.com #
# remove NO SPAM to email, or use form on website #
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help running a very very very simple code olivier.melcher Java 8 05-12-2008 07:51 PM
CGI.PM Very very simple question AMT2K5 Perl Misc 3 12-02-2005 05:18 PM
Very very very basic question Peter C Programming 14 02-14-2005 09:46 AM
Quick Book file access very very very slow Thomas Reed Computer Support 7 04-09-2004 08:09 PM
very Very VERY dumb Question About The new Set( ) 's Raymond Arthur St. Marie II of III Python 4 07-27-2003 12:09 AM



Advertisments