/    Sign up×
Community /Pin to ProfileBookmark

need help with js

Hi, i’m trying to write code in php with javascripts, to see the sample please see sample from ask.com where you see image background with search text field form on the forground behind image.

I have developed that when loading is showing first style backgroundimage, then person select image from the menu it will change style background image, the problme is that every time select image from the menu it will show on different page with different url address.

I want to show in same page using (div) on the line where it said “<img name=”previewpic” src=”background/City/Snow-city2.png” width=150 height=113 border=1>’ how can i write code in with div to show in same page when person select images from the menu.

please see code:

[CODE]<SCRIPT LANGUAGE=”JavaScript”>

function previewPic(sel) {
document.previewpic.src = “” + sel.options[sel.selectedIndex].value;
}
function showPic(sel) {
images = new Array();
images[1] = “background/City/Nice-City-1.png”;
images[2] = “background/City/Nice-City-3.png”;
images[3] = “background/City/Snow-city.png”;
images[4] = “background/City/Snow-city2.png”;
images[5] = “background/City/Snow-city3.png”;
images[6] = “background/City/Snow-city2.png”;
window.location.href = images[sel.selectedIndex+1];
}
// End –>
</script>
</HEAD>

<!– STEP TWO: Copy this code into the BODY of your HTML document –>

<BODY>

<center>
<form name=picform>
<select name=selbox size=1 onChange=”previewPic(this)”>
<option value=”background/City/Nice-City-1.png”>Axe
<option value=”background/City/Nice-City-3.png”>Castle
<option value=”background/City/Snow-city.png”>Iceberg
<option value=”background/City/Snow-city2.png”>Ocean
<option value=”background/City/Snow-city3.png”>Olympus
<option value=”background/City/Snow-city2.png”>Temple
</select>
<p>
<img name=”previewpic” src=”background/City/Snow-city2.png” width=150 height=113 border=1>
<p>
<input type=button value=”Show Image” onclick=”showPic(this.form.selbox)”>
</form>
</center>
</p>
</p>
</body>
</html>[/CODE]

please help thansk.

AM

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@web_bertMar 31.2009 — You are using window.location.href which is going to point the browser at a new url, so the page will reload. All you need to do is change the class name of the div with the previewPic function. Then you can specify the images in your css.
Copy linkTweet thisAlerts:
@AlidadauthorMar 31.2009 — i honestly don't get it, can you possible to write sample please. or full code for that line, that would help me to undersand, i'm just rookie.

thanks.

AM
Copy linkTweet thisAlerts:
@KorMar 31.2009 — <i>
</i>&lt;input type=button value="Show Image" onclick="showPic(this.form.selbox)"&gt;

Think a little: [B]this.form.selbox[/B] is the reference of the select object, but you need the select's object's [B]value[/B]

There are some other errors there, but I hope I was to put you on the right direction: [B]showPic(selbox.value)[/B]

In case of form's elements, the reference can be send straight by name.
Copy linkTweet thisAlerts:
@AlidadauthorMar 31.2009 — so what i did change is

onChange="previewPic(this)"

to

onChange="previewPic(this.value);"



document.previewpic.src = "" + sel.options[sel.selectedIndex].value;


to

document.previewpic.src = sel;

but i'm still showing that when load page, is show default image, but when i selected image from menu is showing white background, did i missed something!

AM
×

Success!

Help @Alidad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...