Link to home
Start Free TrialLog in
Avatar of ALEx604
ALEx604

asked on

Default image used when variable is not found

For an HTML based Webpage ( No CGI access btw)
EXAMPLE: (STARTS)
<body>
<script>
var mydate=new Date()
var day=mydate.getDay()
var month=mydate.getMonth()+1
if (month < 10)
month="0"+month
var day=mydate.getDate()
var newimg="http://www.myhomepage.com/img/today"+month+day+".gif"

document.write('<img src="`newimg`">`)
</script>
EXAMPLE: (ENDS)
This script works fine, as long as I have an image with the date in the name of the image in the "img" folder,
for example a file called "today1225.gif" is an image for christmas
What I want is to change this so that if there is no image in the img folder to use on that day, it uses a "default.gif" instead.
I don't want to use something like an alt text, I'd rather have an alternative default.gif

I was hoping there is a way to do this without making a database in the script of every image in the folder.
A javascript equal too... document.write('<img src="./img/today"+month+day+".gif alt img="./img/default.gif">`)
but the command "alt img" isn't real.

Any Ideas?

ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial