aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript troubles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript troubles" Watch "JavaScript troubles" New topic
Author

JavaScript troubles

Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44
Ok , the problem is

Scroll down to the div element with id value maps and replace the line
<img id="sky" src="sky0.jpg" alt="" />
with a script element that writes the following html code:
<img id='sky' src='mapNum.jpg' alt=' ' />
were mapNum is the value of the mapNum Variable.

I've been redoing this several times and can't seem to get everywhere,
I had to do a similar thing with the clock but got it to work right away.

Any help is greatly appreciated!

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Please take the time to choose the correct forum for your posts. This forum is for questions on Java. For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44
I just wish someone could help me.......
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

You haven't done a particularly god job of letting us know what problem you are having.
Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44
Bear Bibeault wrote:You haven't done a particularly god job of letting us know what problem you are having.


# <script type="text/javascript">
# document.write('<img id="sky" ' />');
# </script>

That's what I have so far, I don't know how to explain it any better, I copied the question out of the book, did my best to try it for myself and the image is not displaying.
I need help to figure out what is wrong with my script and why it is not doing what the book wants it to do.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

When posting HTML be sure to click the 'disable HTML' checkbox.

First, you need to fix your syntax. Your quoting is wrong.

Second, if the image tag doesn't have a src attribute to identify its image file, of course nothing will appear.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1726
    
  12

Nick,

I still don't understand what the question is.

What have you tried? What is is supposed to do? What part(s) of what it's supposed to do isn't it doing?

"It doesn't work" doesn't help anyone to help you.


When you do things right, people won't be sure you've done anything at all.
Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44
Bear Bibeault wrote:When posting HTML be sure to click the 'disable HTML' checkbox.

First, you need to fix your syntax. Your quoting is wrong.

Second, if the image tag doesn't have a src attribute to identify its image file, of course nothing will appear.


Well here is what I have now
If the quoting is still wrong that's what I need help on, and what that last part posted isn't what I wanted to post anyways, it did have a src
Can you help me from this further? It is still not showing an image.

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1726
    
  12

That quoting doesn't look like the quoting in the example:



EDIT -- Crap.... the stupid forum ate my code.
Check line 45 in the example
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

OK, that looks a little better.

Is there really an image file with the resulting name in the same folder as the HTML file?

By the way, using a tool like Firebug in Firefox will let you look at the active HTML DOM so you can see what the result of your statement actually becomes in the DOM.

Chrome also has such tools.
Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44
Bear Bibeault wrote:OK, that looks a little better.

Is there really an image file with the resulting name in the same folder as the HTML file?

By the way, using a tool like Firebug in Firefox will let you look at the active HTML DOM so you can see what the result of your statement actually becomes in the DOM.

Chrome also has such tools.


well the mapNum variable is referencing the getMap() function,
My book says The getMap() function which returns a number from 0 to 23. The number matches the number of the sky map image to show based on the current date and time. That function has been placed in an external javascript file named datetime.js which you can see I accessed in the top of the code.
The timeStr also refers to a function in that file and it actually works. In the project folder there are 0-23 images and I guess the function reads the time and displays the apropriate picture.

My task was this
4. Scroll down the file to the div element with the id value maps and replace the line
(which is now gone) with a script element that writes the following html code.

where mapNum is the value of the mapNum variable
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Your post is screwed up again. Please pay attention to the checkboxes beneath the posting box and set them appropriately.
Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44
it screwed up my code again

Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44
Hopefully all that information helps. There is not a specific image with that name as you asked before, the function selects the image depending on the time. I am pretty sure thats how it works.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
And the function getMap is located where?

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaScript troubles