473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

changing background image? Help?

Something goes wrong in my script. I'm all new to it so i don't know
much yet.
I have a set of buttons. And when you click on either of them, the
background image will change. Only it's not working. It works when i
click on one, but then when i want to click on another, it's not
working.
What am i doing wrong?
thanks in advance

<html><head><title></title>

<script type="text/javascript">
var buttons="<img src=\"buttonrood2.jpg\"
onclick=\"print_waarde0()\"><img src=\"buttongroen2.jpg\"
onclick=\"print_waarde1()\"><img src=\"buttongeel2.jpg\"
onclick=\"print_waarde2()\"><img src=\"buttonblauw2.jpg\"
onclick=\"print_waarde3()\"><img src=\"buttonoranje2.jpg\"
onclick=\"print_waarde4()\"><img src=\"buttonmagenta2.jpg\"
onclick=\"print_waarde5()\"><img src=\"buttoncyaan2.jpg\"
onclick=\"print_waarde6()\">";

function print_waarde0() {
var a = "achtergrondrood.jpg";
var top = '<html><body background="' + a + '">';
var bottom = "</body></html>";
document.write(top+buttons+bottom);
}

function print_waarde1() {
var b = "achtergrondgroen.jpg";
var top1 = '<html><body background="' + b + '">';
var bottom1 = "</body></html>";
document.write(top1+buttons+bottom1);
}

function print_waarde2() {
var c = "achtergrondgeel.jpg";
var top2 = '<html><body background="' + c + '">';
var bottom2 = "</body></html>";
document.write(top2+buttons+bottom2);
}

function print_waarde3() {
var d = "achtergrondblauw.jpg";
var top3 = '<html><body background="' + d + '">';
var bottom3 = "</body></html>";
document.write(top3+buttons+bottom3);
}

function print_waarde4() {
var e = "achtergrondoranje.jpg";
var top4 = '<html><body background="' + e + '">';
var bottom4 = "</body></html>";
document.write(top4+buttons+bottom4);
}

function print_waarde5() {
var f = "achtergrondmagenta.jpg";
var top5= '<html><body background="' + f + '">';
var bottom5 = "</body></html>";
document.write(top5+buttons+bottom5);
}

function print_waarde6() {
var g = "achtergrondcyaan.jpg";
var top6 = '<html><body background="' + g + '">';
var bottom6 = "</body></html>";
document.write(top6+buttons+bottom6);


}

</script>

</head>
<body background="paeceachtergrond.jpg" bgproperties="fixed">
<h2>Welkom op Understanding Colors!</h2><br>
<font face="georgia">
Do you want to change the background?<br>
Choose from the following buttons and click on one.<br>

<body>

<img src="buttonrood2.jpg" onclick="print_waarde0()">
<img src="buttongroen2.jpg" onclick="print_waarde1()">
<img src="buttongeel2.jpg" onclick="print_waarde2()">
<img src="buttonblauw2.jpg" onclick="print_waarde3()">
<img src="buttonoranje2.jpg" onclick="print_waarde4()">
<img src="buttonmagenta2.jpg" onclick="print_waarde5()">
<img src="buttoncyaan2.jpg" onclick="print_waarde6()">

<br>
<br>

Op deze site kan je alles lezen over kleur en wat er mee te maken
heeft.<br>

</body>
</html>
Jul 23 '05 #1
4 5448
Gequina wrote on 21 okt 2004 in comp.lang.javascript:
Something goes wrong in my script. I'm all new to it so i don't know
much yet.
I have a set of buttons. And when you click on either of them, the
background image will change. Only it's not working. It works when i
click on one, but then when i want to click on another, it's not
working.
What am i doing wrong?
thanks in advance


Als je document.write gebruikt,
vernietig je de huidige pagina INCLUSIEF!!! aanwezige javascript.

Gebruik javascript en css:

<body>
Probeer dit eens:<br><br>
<button
onclick="document.body.style.backgroundColor='gree n'">
Groen</button>
<button
onclick="document.body.style.backgroundColor='red' ">
Rood</button>
<button
onclick="document.body.style.backgroundColor='yell ow'">
Geel</button>
</body>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #2
Gequina wrote:
Something goes wrong in my script. I'm all new to it so i don't know
much yet.
I have a set of buttons. And when you click on either of them, the
background image will change. Only it's not working. It works when i
click on one, but then when i want to click on another, it's not
working.
What am i doing wrong?
thanks in advance
<--snip-->
function print_waarde0() {
var a = "achtergrondrood.jpg";
var top = '<html><body background="' + a + '">';
var bottom = "</body></html>";
document.write(top+buttons+bottom);
}


You are using document.write after the page has finished loading. That
removes the current page and replaces it with your new code. That means
your script is no longer present so it can't be run. Look at the FAQ and
its DynWrite function to modify a page.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #3
ok, ergens begrijp ik het wel, maar niet helemaal. Ik ben echt nieuw
hierin, maar moet aankomende maandag wel een presentatie hierover houden
en t gaat lastiger dan dat ik dacht.
Ik snap nu niet wat ik weg moet halen en wat moet blijven staan. Kan je
me helemaal helpen met het hele script? sorry als ik lastig ben, het
hoeft niet.

moeten al deze vakjes weg?

function print_waarde0() {
var a = "achtergrondrood.jpg";
var top = '<html><body background="' + a + '">';
var bottom = "</body></html>";
document.write(top+buttons+bottom);
}

*zucht*...sorry, ik ben het helemaal kwijt nu.

en je zegt dat ik javascript+css moet doen. Maar hoe schrijf ik dat op?
< script type="text/javascript/css" > ???
of anders?

ok, wat ik nu in elkaar heb gefrabiceerd is dit:
<html><head><title></title>

<script type="text/javascript">
var buttons="<img src=\"buttonrood2.jpg\"
onclick=\"print_waarde0()\"><img src=\"buttongroen2.jpg\"
onclick=\"print_waarde1()\"><img src=\"buttongeel2.jpg\"
onclick=\"print_waarde2()\"><img src=\"buttonblauw2.jpg\"
onclick=\"print_waarde3()\"><img src=\"buttonoranje2.jpg\"
onclick=\"print_waarde4()\"><img src=\"buttonmagenta2.jpg\"
onclick=\"print_waarde5()\"><img src=\"buttoncyaan2.jpg\"
onclick=\"print_waarde6()\">";
</script>
</head>

<body background="paeceachtergrond.jpg" bgproperties="fixed">
<h2>Welkom op Understanding Colors!</h2><br>

<body>

<font face="georgia">
Wil je de achtergrond kleur veranderen?<br>
Kies dan uit 1 van de volgende buttons.<br>

<script type="text/javascript">
<button
onclick="document.body.style.backgroundImage='acht ergrondrood.jpg'">
<img src="buttonrood2.jpg"></button>
<button
onclick="document.body.style.backgroundImage='acht ergrondgroen.jpg'">
<img src="buttongroen2.jpg"></button>
<button
onclick="document.body.style.backgroundImage='acht ergrondgeel.jpg'">
<img src="buttongeel2.jpg"></button>
<button
onclick="document.body.style.backgroundImage='acht ergrondblauw.jpg'">
<img src="buttonblauw2.jpg"></button>
<button
onclick="document.body.style.backgroundImage='acht ergrondoranje.jpg'">
<img src="buttonoranje2.jpg"></button>
<button
onclick="document.body.style.backgroundImage='acht ergrondmagenta.jpg'">
<img src="buttonmagenta2.jpg"></button>
<button
onclick="document.body.style.backgroundImage='acht ergrondcyaan.jpg'">
<img src="buttoncyaan2.jpg"></button>

</script>

<br>
<br>

Op deze site kan je alles lezen over kleur en wat er mee te maken
heeft.<br>

</body>
</html>

ik ben t echt helemaal kwijt, please help me? haha
alvast bedankt!
xxx

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4
Gequina girl wrote on 21 okt 2004 in comp.lang.javascript:
<script type="text/javascript">
<button
onclick="document.body.style.backgroundImage='acht ergrondrood.jpg'">
<img src="buttonrood2.jpg"></button>

Heb je mijn code wel geprobeerd op zich zelf? Dat is werkende code,
hoor, zonder 1 toevoeging in een file test.html te zetten en te runnen
in de IE.

Dan zou je moeten zien dat <button> gewoon in HTML saat en niet in
<script> en dat onclick vanzelf een javascript uitvoert.

<script type="text/javascript">
var buttons="<img src=\"buttonrood2.jpg\"
onclick=\"print_waarde0()\"><img src=\"buttongroen2.jpg\"
onclick=\"print_waarde1()\"><img src=\"buttongeel2.jpg\"
onclick=\"print_waarde2()\"><img src=\"buttonblauw2.jpg\"
onclick=\"print_waarde3()\"><img src=\"buttonoranje2.jpg\"
etc ....
Dat stuk heb je helemaal niet nodig.
Kan je me helemaal helpen met het hele script?
Nee, daar is een NG echt niet voor. Dan zou je iemand in moeten huren.
Ik ben echt nieuwhierin, maar moet aankomende maandag wel een
presentatie hierover houden en t gaat lastiger dan dat ik dacht.


Een presentatie moet je toch houden over iets wat je grondig begrijpt?
Je hebt toch nog heet hele weekend?

Gooi je oude code nu eens helemaal weg en begin met mijn eerste aanleg.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
8
by: Udo Marx | last post by:
Hello to ciwas! Is there a way to change the bullet form, color, etc, of the element <li> under<ul> via css? Any reply will be appreciated. -- Freundliche Gruesse, Netzteil - Udo Marx...
3
by: Michael Eisenstadt | last post by:
What are the coding options for client-side image size changing? I want the viewer to be able to switch between two different sizes of the same image with his/her mouse. Thanks in advance for...
6
by: John Ortt | last post by:
Hi there everyone, I have a part info form which has a faded image of our company logo as a background. I want to replace the faded image with a bright red warning image on items which have run...
4
by: Chris Mahoney | last post by:
Hi Currently I am setting the background image of my page by using the following code: <style type="text/css"> BODY { BACKGROUND-IMAGE: url(myimage.jpg) } </style> What I would like to do...
2
by: Jean Pierre Daviau | last post by:
Hi , a simple one, document.body.background = document.getElementById('item').value document.getElementById('item').value (an input text) return the right value for the image....
3
by: rvanwaarden | last post by:
Hi All, I am relatively new to this game and I am running up against a problem trying to change the background image in my table. The idea is that when you click on the link, the javascript will...
8
by: John | last post by:
Hi Pasrt of HTML - <div class='button'><input type='image' src='/images/check1.jpg'></input></div> Part of CSS - ..button {background-image: url(/images/check1.jpg); background-repeat:
0
by: zeckdude | last post by:
Hi, I am having some issues with my site. I have a main Nav with four links that load in 4 different sections. You can see the page I am working on here:...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.