Click to See Complete Forum and Search --> : Do not refresh frame onClick


BaileyBoy
11-04-2003, 10:38 PM
This is also in the JavaScript thread - I may be grasping at straws.

A site I'm working on needs a preview picture script - which it does in its own frame. The larger image appears in another frame, however,
the side frame refreshes, which I cannot have...I need help!

HERE'S AN ABBREVIATED VERSION OF THE SCRIPT (see <!--CONCERN-->):

<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function previewPic(sel) {
document.previewpic.src = "" + sel.options[sel.selectedIndex].value;
}
function showPic(sel) {
images = new Array();
images[1] = "../main_pages/main1.html";
images[2] = "../main_pages/main2.html";
images[3] = "../main_pages/main3.html";
parent.MAIN.location.href = images[sel.selectedIndex+1];
}
// End -->
</script>
</head>

<body>
<form name=picform>
<img name="previewpic" src="preview_pics/acheff_sm.gif" width=150 height=113 border=0>
<select name=selbox size=1 onChange="previewPic(this)">
<option value="preview_pics/acheff_sm.gif">William Acheff
<option value="preview_pics/adams_sm.gif">Peter Adams
<option value="preview_pics/afsary_sm.gif">Cyrus Afsary
</select>

<!-- HERE'S THE CONCERN BELOW -->
<INPUT type="image" src="preview_pics/show_image.jpg" border="0" onclick="showPic(this.form.selbox)">
<!-- THE SIDE FRAME REFRESHES ITSELF WHENEVER THE 'SHOW IMAGE' IS CLICKED -->

</form>
</body>

SEE IT IN ACTION AT http://www.baileycreative.com/masters2004

Many Thanks in advance!

gil davis
11-04-2003, 10:43 PM
The default action of a type="image" is SUBMIT. That is why your page refreshes. Add ";return false" to the onclick.
<INPUT type="image" ... onclick="showPic(this.form.selbox);return false">

BaileyBoy
11-04-2003, 11:32 PM
I thank you in JavaScript I thank you in HTML - worked great