473,224 Members | 1,572 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,224 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 5442
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:...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.