help

P

Prophet

I have figured out how to have text change according to the day of the
week - what I want to do is to ad an accompanying picture, which also
changes according to the day of the week.

Any ideas on how to help me??????

This is how I did the text:

<script language="JavaScript">
<!--
function quick() {

var mydate=new Date()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var qfarray=new Array("text 1.",
"text 2.",
"text3.",
"text4",
"text5.",
"text6.",
"text7.")
document.write("<small><font face='Times New Roman'>"+qfarray[day])}
// -->
</script>


<script language="JavaScript">
<!--
quick()
//-->

</script>
 
W

web.dev

Prophet,

Here's a quick and dirty solution You can do the following:
Make an array with path to your seven images:

var imgarray = new Array("../images/day1.jpg", "../images/day2.jpg",
etc..);

Then to display your image:

document.write("<img src = '" + imgarray[day] + "'/>");

:) Hope it helps.
 
P

Prophet

So I tried it, but it does not show the actual picture - there is just the
box which shows that there should be a picture in its place
 
L

Lee

Prophet said:
So I tried it, but it does not show the actual picture - there is just the
box which shows that there should be a picture in its place

Make sure the paths in the array actually point to your images.
To be absolutely sure, you can give the full URL
("http://whatever/whatever.gif").

When responding to posts, you should put your response *after* the
text you're responding to, and, in the future, please try to think
of a subject line that tells us what sort of problem you need help
with. Nearly everyone who starts a thread is looking for "help".
 
W

web.dev

Are you sure the path to where your image is correct? Or if the image
even exists? If yes to both, then you could even consider that the
browser might not even know how to display that picture, which are rare.
 
P

Prophet

web.dev said:
Prophet,

Here's a quick and dirty solution You can do the following:
Make an array with path to your seven images:

var imgarray = new Array("../images/day1.jpg", "../images/day2.jpg",
etc..);

Then to display your image:

document.write("<img src = '" + imgarray[day] + "'/>");

:) Hope it helps.

Now that I have the picture showing, how do I insert formatting commands
such as 'center' or 'height = 78' etc.
 
P

Prophet

Lee said:
Prophet said:

Make sure the paths in the array actually point to your images.
To be absolutely sure, you can give the full URL
("http://whatever/whatever.gif").

When responding to posts, you should put your response *after* the
text you're responding to, and, in the future, please try to think
of a subject line that tells us what sort of problem you need help
with. Nearly everyone who starts a thread is looking for "help".

When responding, the cursor automatically goes to the *TOP* of the page, so
I naturally just start typing - I knew that 'help' was not a very good
subject, but I could not think of anything that was eye catching and matched
the nature of the question.

please bare with me as I am learning!

Thank you for the guidance - Mark
 
R

Richard Cornford

Now that I have the picture showing, how do I insert
formatting commands such as 'center' or 'height = 78' etc.

Formatting isn't done with commands, it is presentational so it is done
with CSS, with the exception of the dimensions of the image, which
probably should be in the form of attributes in the CSS string. If all
of the images are the same size then the attributes can be written into
the string of HTML that is being written. If the image sizes vary then
the IMG URLs and width and height information could be stored in an
array of objects, e.g.:-

var imgData = [
{
url:'images/sunday.gif',
width:50,
height:50
},
{
url:'images/monday.gif',
width:60,
height:50
},
{
url:'images/tuesday.gif',
width:70,
height:50
},
{
url:'images/wednesday.gif',
width:50,
height:60
},
{
url:'images/thursday.gif',
width:50,
height:70
},
{
url:'images/friday.gif',
width:90,
height:90
},
{
url:'images/saturday.gif',
width:30,
height:150
}
];

The data can be concatenated into a string, or assembled into an Array
of strings that is later joined to form the HTML output:-

var imgOut = [
'<img src="',
'', // index 1
'" width="'
'', // index 3
'" height="',
'', // index 5
'">'
];

var day=mydate.getDay()

The object for a particular day can be recovered from the array in the
same way that the URL string has previously been recovered, by indexing
the Array with the week day number:-

var imgDayObject = imgData[day];

- and the individual pieces of information retrieved from that object by
name (and assigned to slots in the output array in this case):-

imgOut[1] = imgDayObject.url;
imgOut[3] = imgDayObject.width;
imgOut[5] = imgDayObject.height;

And then the whole can be output using - document.write - (or other
techniques). In this case the array is assembled into a single string
using the Array's join method (joining the Array elements with an empty
string between elements, so as not to alter the output):-

document.write( imgOut.join('') );

Richard.
 
R

Richard Cornford

Prophet said:
Lee wrote:
When responding, the cursor automatically goes to the *TOP* of
the page, so I naturally just start typing

The cursor starting at the top provides an opportunity to work down
through the document snipping the parts that are not going to be
responded to, and inserting responses after whatever is left.
- I knew that 'help' was not a very good subject,
but I could not think of anything that was eye catching

Don't try to be eye catching, try to be informative. A subject header
that states the real subject is only likely to result in people who have
no interest in the subject being put off reading it, and those
individuals probably wouldn't be much help anyway (but you still don't
want to be wasting their time in case you later have a question with a
subject in which they are interested).
and matched the nature of the question.

The nature of the question is not necessarily relevant either. It is the
_subject_ of the question that should appear in the subject header. The
subject here appears to be; displaying one of a selection of images
based on the day of the week.
please bare with me as I am learning!

Then you will want to read this group's FAQ:-

<URL: http://jibbering.com/faq >

- and save anyone else having to point out to you anything else that it
covers.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top