Second question of the day. Sorry to be greedy. I have some javascript which repeats large blocks of code with a few subtle difference. I was wondering how to trim it. Ideally I would like to refernce as much as possible from an external .js file. But I am not sure which parts can be cut out. The code is in the body of the html.
The page has about 50 different images and each leads to a chunk of code which is an onclick event…The middle part of each chunck does not vary.
Each section looks like this (i have changed the bits that vary to “VARIES”
[CODE]<TD vAlign=top width=45><A href=”#topanchor”
onclick=”
VARIES.src=’http://hardyart.co.uk/frame/VARIES.jpg’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
document.getElementById(‘VARIES’).style.backgroundImage =
‘url(‘http://hardyart.co.uk/frame/VARIES.jpg’)’;
frameselected = ‘VARIES’; frametitle = ‘VARIES’; frameprice = VARIES; framethick = VARIES;
THIS PART DOES NOT VARY check();
document.calc2.Title.value = ‘Frame for print ‘ + ebaytitle;
document.calc2.Print.value = ‘£’ + printprice;
document.calc2.Total.value = ‘(print and frame) £’ + ((Math.round((calcaddframe(setup,backbrdprice,barrierbrdprice,glassprice,innermprice,framedarea,outermprice,framethick,borderwidth,borderheight,frameprice,slipthick,picturewidth,pictureheight,slipprice)+printprice)/5)*5)-0.01);
document.calc2.Link.value = ‘http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=’ + testmeout;
document.calc2.Frame.value = frametitle + ‘ (‘ + frameselected + ‘)’;
document.calc2.Mount1.value = ‘Outer Mount: ‘ + outermtitle + ‘ (‘ + outermselected + ‘)’;
document.calc2.Mount2.value = ‘Inner Mount: ‘ + innermtitle + ‘ (‘ + innermselected + ‘)’;
document.calc2.Slip.value = sliptitle + ‘ (‘ + slipselected + ‘)’;
document.calc3.D.value = ‘eBay Item Number: ‘ +testmeout; document.calcprice.p.value = ‘Print only: £’ + printprice + ‘ ; Framed print: £’ + ((Math.round((calcaddframe(setup,backbrdprice,barrierbrdprice,glassprice,innermprice,framedarea,outermprice,framethick,borderwidth,borderheight,frameprice,slipthick,picturewidth,pictureheight,slipprice)+printprice)/5)*5)-0.01);”> THEN IT VARIES AGAIN
<IMG name=imagef1 src=”http://hardyart.co.uk/frame/VARIES.jpg” Title=”VARIES” border=0></A></TD>
Cheers