473,698 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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><ti tle></title>

<script type="text/javascript">
var buttons="<img src=\"buttonroo d2.jpg\"
onclick=\"print _waarde0()\"><i mg src=\"buttongro en2.jpg\"
onclick=\"print _waarde1()\"><i mg src=\"buttongee l2.jpg\"
onclick=\"print _waarde2()\"><i mg src=\"buttonbla uw2.jpg\"
onclick=\"print _waarde3()\"><i mg src=\"buttonora nje2.jpg\"
onclick=\"print _waarde4()\"><i mg src=\"buttonmag enta2.jpg\"
onclick=\"print _waarde5()\"><i mg src=\"buttoncya an2.jpg\"
onclick=\"print _waarde6()\">";

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

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

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

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

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

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

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


}

</script>

</head>
<body background="pae ceachtergrond.j pg" bgproperties="f ixed">
<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="buttonrood 2.jpg" onclick="print_ waarde0()">
<img src="buttongroe n2.jpg" onclick="print_ waarde1()">
<img src="buttongeel 2.jpg" onclick="print_ waarde2()">
<img src="buttonblau w2.jpg" onclick="print_ waarde3()">
<img src="buttonoran je2.jpg" onclick="print_ waarde4()">
<img src="buttonmage nta2.jpg" onclick="print_ waarde5()">
<img src="buttoncyaa n2.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 5480
Gequina wrote on 21 okt 2004 in comp.lang.javas cript:
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="docume nt.body.style.b ackgroundColor= 'green'">
Groen</button>
<button
onclick="docume nt.body.style.b ackgroundColor= 'red'">
Rood</button>
<button
onclick="docume nt.body.style.b ackgroundColor= 'yellow'">
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 = "achtergrondroo d.jpg";
var top = '<html><body background="' + a + '">';
var bottom = "</body></html>";
document.write( top+buttons+bot tom);
}


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.javas cript 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 = "achtergrondroo d.jpg";
var top = '<html><body background="' + a + '">';
var bottom = "</body></html>";
document.write( top+buttons+bot tom);
}

*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><ti tle></title>

<script type="text/javascript">
var buttons="<img src=\"buttonroo d2.jpg\"
onclick=\"print _waarde0()\"><i mg src=\"buttongro en2.jpg\"
onclick=\"print _waarde1()\"><i mg src=\"buttongee l2.jpg\"
onclick=\"print _waarde2()\"><i mg src=\"buttonbla uw2.jpg\"
onclick=\"print _waarde3()\"><i mg src=\"buttonora nje2.jpg\"
onclick=\"print _waarde4()\"><i mg src=\"buttonmag enta2.jpg\"
onclick=\"print _waarde5()\"><i mg src=\"buttoncya an2.jpg\"
onclick=\"print _waarde6()\">";
</script>
</head>

<body background="pae ceachtergrond.j pg" bgproperties="f ixed">
<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="docume nt.body.style.b ackgroundImage= 'achtergrondroo d.jpg'">
<img src="buttonrood 2.jpg"></button>
<button
onclick="docume nt.body.style.b ackgroundImage= 'achtergrondgro en.jpg'">
<img src="buttongroe n2.jpg"></button>
<button
onclick="docume nt.body.style.b ackgroundImage= 'achtergrondgee l.jpg'">
<img src="buttongeel 2.jpg"></button>
<button
onclick="docume nt.body.style.b ackgroundImage= 'achtergrondbla uw.jpg'">
<img src="buttonblau w2.jpg"></button>
<button
onclick="docume nt.body.style.b ackgroundImage= 'achtergrondora nje.jpg'">
<img src="buttonoran je2.jpg"></button>
<button
onclick="docume nt.body.style.b ackgroundImage= 'achtergrondmag enta.jpg'">
<img src="buttonmage nta2.jpg"></button>
<button
onclick="docume nt.body.style.b ackgroundImage= 'achtergrondcya an.jpg'">
<img src="buttoncyaa n2.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.javas cript:
<script type="text/javascript">
<button
onclick="docume nt.body.style.b ackgroundImage= 'achtergrondroo d.jpg'">
<img src="buttonrood 2.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=\"buttonroo d2.jpg\"
onclick=\"print _waarde0()\"><i mg src=\"buttongro en2.jpg\"
onclick=\"print _waarde1()\"><i mg src=\"buttongee l2.jpg\"
onclick=\"print _waarde2()\"><i mg src=\"buttonbla uw2.jpg\"
onclick=\"print _waarde3()\"><i mg src=\"buttonora nje2.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
2484
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 backgound colour? I have a table with a background that has a picture. When the user hovers over the picture I want the background to change to the background colour of the rest of the page, as if to make the picture disappear.
8
61494
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 http://www.netzteil.com mailto:marx@netzteil.com
3
2424
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 your help. Michael Eisenstadt
6
9477
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 out of purchasing cover. I am nearly there, the only problem is that the code below only changes the image background for text and combo-box backgrounds, it doesn't apply it to the whole form.
4
3780
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 is change the background image dynamically. My guess
2
1264
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. Why the background is not changed? Thanks for your attention.
3
1431
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 change the table background. The table code looks like this <table id="tableVert" style="margin-left: auto; margin-right: auto; text-align: left; width: 100%; height: 500px; background-image: url();" border="0" cellpadding="0" cellspacing="0"> ...
8
14247
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
1379
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: http://idea-palette.com/official/newofficialsite4.html What I am trying to do is, when a user clicks on another Main Nav button, such as 'Web Projects', the background-image changes to another image that shows the lightbulb being on. I also want it to change back the background-image...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.