However, these can also be changed by editing the script. For example, to set a separate
height for each image, you??™d first add the following array:
var chosenHeight=new Array();
chosenHeight[0]="200";
chosenHeight[1]="500";
chosenHeight[2]="400";
And you??™d next add the following line to the function:
document.getElementById('randomImage').setAttribute
??('height',chosenHeight[getRan]);
Remember, however, the advice earlier about the page reflowing if the image dimensions
vary??”if you have images of differing sizes, your design will need to take this into account.
Required files The image-randomizer-starting-point folder from the chapter
4 folder.
What you??™ll learn How to create an image randomizer using PHP.
Completed files The image-randomizer-php folder in the chapter 4 folder.
If you have access to web space that enables you to work with PHP, it??™s simple to create an
equivalent to the JavaScript exercise using PHP. The main benefit is that users who disable
JavaScript will still see a random image, rather than just the default. Note that you need
some method of running PHP files to work on this exercise, such as a local install of
Apache. Note also that prior to working through the steps, you should remove the HTML
document??™s script element, and you should also amend the title element??™s value,
changing it to something more appropriate.
Creating a PHP-based image randomizer
THE ESSENTIAL GUIDE TO CSS AND HTML WEB DESIGN
142
1.
Pages:
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227