I have an html img with a source of 'lbug.gif'. I want to be able to change
out the source of the img by clicking a button. Here's my code:
function swapPic()
{
if (document.Form1 .imgBug.src = "lbug.gif")
{
document.Form1. imgBug.src = "stopbug.jp g";
}
else if (document.Form1 .imgBug.src = "stopbug.jp g")
{
document.Form1. imgBug.src = "lbug.gif"
}
}
When I click the button the 1st time, the code executes as expected. Each
successive
time I click the button, the same code executes which is the:
if (document.Form1 .imgBug.src = "lbug.gif")
{
document.Form1. imgBug.src = "stopbug.jp g";
}
And the source never switches back to 'lbug.gif'
What concept am I missing here?
TIA,
Marc Miller
'Confused in Northeast Penna.' 9 1304
Marc Miller wrote: When I click the button the 1st time, the code executes as expected. Each successive time I click the button, the same code executes which is the:
if (document.Form1 .imgBug.src = "lbug.gif") { document.Form1. imgBug.src = "stopbug.jp g"; }
And the source never switches back to 'lbug.gif'
What concept am I missing here?
The difference between an assignment "=" and a comparison "==",
and a reasonable Subject header.
<URL:http://jibbering.com/faq/>
PointedEars
--
This above all: To thine own self be true.
-- William Shakespeare (1564-1616)
"Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message
news:61******** ********@Pointe dEars.de... Marc Miller wrote:
When I click the button the 1st time, the code executes as expected. Each successive time I click the button, the same code executes which is the:
if (document.Form1 .imgBug.src = "lbug.gif") { document.Form1. imgBug.src = "stopbug.jp g"; }
And the source never switches back to 'lbug.gif'
What concept am I missing here? The difference between an assignment "=" and a comparison "==", and a reasonable Subject header.
<URL:http://jibbering.com/faq/>
PointedEars
-- This above all: To thine own self be true. -- William Shakespeare (1564-1616)
Thomas,
Thanks for your response and you're right, a reasonable subject header is
much more appropriate.
Interestingly enough, I used the comparasion "==" in my first attempt ( in
the 'if' and 'else if' lines) and nothing happened.
I then changed it to the assignment "=" and, voila, the 'if' line works all
the time, except that it does not
correctly identify the 'src' attribute of the image.
I tried using 'switch' but that seems not to be an option at all.
By the way, my platform it asp.net 2003, .NET framework 1.1.
Thank again,
Marc Miller
Marc Miller wrote: "Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message news:61******** ********@Pointe dEars.de... Marc Miller wrote:
When I click the button the 1st time, the code executes as expected. Each successive time I click the button, the same code executes which is the:
if (document.Form1 .imgBug.src = "lbug.gif") { document.Form1. imgBug.src = "stopbug.jp g"; }
And the source never switches back to 'lbug.gif'
What concept am I missing here?
The difference between an assignment "=" and a comparison "==", and a reasonable Subject header.
<URL:http://jibbering.com/faq/>
PointedEars
-- This above all: To thine own self be true. -- William Shakespeare (1564-1616)
Thomas,
Thanks for your response and you're right, a reasonable subject header is much more appropriate.
Interestingly enough, I used the comparasion "==" in my first attempt ( in the 'if' and 'else if' lines) and nothing happened.
I then changed it to the assignment "=" and, voila, the 'if' line works all the time, except that it does not correctly identify the 'src' attribute of the image.
I tried using 'switch' but that seems not to be an option at all.
By the way, my platform it asp.net 2003, .NET framework 1.1.
Thank again, Marc Miller
Use the "==" operator, then send an alert if it is not true so you can
see what the value is. It may be adding
"http://www.yourdomain. com/your/path/to/image" to the string as it
loads the image. Thus you would need:
if (document.Form1 .imgBug.src ==
"http://www.yourdomain. com/your/path/to/image/lbug.gif") {
document.Form1. imgBug.src =
"http://www.yourdomain. com/your/path/to/image/stopbug.jpg";
}
- JS http://www.endeavorpub.com
Marc Miller said the following on 4/24/2006 1:41 PM: I have an html img with a source of 'lbug.gif'. I want to be able to change out the source of the img by clicking a button. Here's my code:
function swapPic() { if (document.Form1 .imgBug.src = "lbug.gif")
Is imgBug the ID/NAME of your img element or is the name of an input
element in your form named Form1?
Second: Your if test is not testing for equality, it is testing to see
if it can set the .src property. It can so it passes the if test.
Third: Access images through the images collection.
Fourth: The .src of an img tag is not the filename. It is the fully
qualified path to the image file.
function swapPic(){
if (document.image s['imageNAME'].src.indexOf('l bug.gif') != -1)
{
document.images['imageNAME'].src = 'stopbug.gif';
}
else
{
document.images['imageNAME'].src = 'lbug.gif'
}
}
But even simpler:
function swapPic(){
document.images['imagename'].src=document.i mages['imagename'].src.match('lbu g.gif')?'stopbu g.gif':'lbug.gi f';
}
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
"jshanman" <un**********@s bcglobal.net> wrote in message
news:11******** *************@v 46g2000cwv.goog legroups.com... Marc Miller wrote: "Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message news:61******** ********@Pointe dEars.de... > Marc Miller wrote: > >> When I click the button the 1st time, the code executes as expected. >> Each >> successive time I click the button, the same code executes which is >> the: >> >> if (document.Form1 .imgBug.src = "lbug.gif") >> { >> document.Form1. imgBug.src = "stopbug.jp g"; >> } >> >> And the source never switches back to 'lbug.gif' >> >> >> What concept am I missing here? > > The difference between an assignment "=" and a comparison "==", > and a reasonable Subject header. > > <URL:http://jibbering.com/faq/> > > > PointedEars
> -- > This above all: To thine own self be true. > -- William Shakespeare (1564-1616)
Thomas,
Thanks for your response and you're right, a reasonable subject header is much more appropriate.
Interestingly enough, I used the comparasion "==" in my first attempt ( in the 'if' and 'else if' lines) and nothing happened.
I then changed it to the assignment "=" and, voila, the 'if' line works all the time, except that it does not correctly identify the 'src' attribute of the image.
I tried using 'switch' but that seems not to be an option at all.
By the way, my platform it asp.net 2003, .NET framework 1.1.
Thank again, Marc Miller
Use the "==" operator, then send an alert if it is not true so you can see what the value is. It may be adding "http://www.yourdomain. com/your/path/to/image" to the string as it loads the image. Thus you would need:
if (document.Form1 .imgBug.src == "http://www.yourdomain. com/your/path/to/image/lbug.gif") { document.Form1. imgBug.src = "http://www.yourdomain. com/your/path/to/image/stopbug.jpg"; }
- JS http://www.endeavorpub.com
JS,
That does work, and with the '==' operator and the fully qualified path. I
was
trying to avoid having to change the domain in the path however, to save the
necessity of changing the string every time there is a version
change/testing/and move
to production.
Thanks to all!
Marc Miller
jshanman said the following on 4/24/2006 2:36 PM:
<snip> Use the "==" operator, then send an alert if it is not true so you can see what the value is. It may be adding "http://www.yourdomain. com/your/path/to/image" to the string as it loads the image. Thus you would need:
It does. The .src property of an img object is always a fully qualified
path when your read its .src property.
if (document.Form1 .imgBug.src == "http://www.yourdomain. com/your/path/to/image/lbug.gif") { document.Form1. imgBug.src = "http://www.yourdomain. com/your/path/to/image/stopbug.jpg"; }
You don't have to include the fully qualified path when setting the
..src, the browser will do it for you. But, see my other reply :)
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Marc Miller said the following on 4/24/2006 2:45 PM:
<snip> That does work, and with the '==' operator and the fully qualified path. I was trying to avoid having to change the domain in the path however, to save the necessity of changing the string every time there is a version change/testing/and move to production.
You don't have to change it everytime if you dont worry with the domain
aspect. See my other reply:
function swapPic(){
document.images['imagename'].src=document.i mages['imagename'].src.match('lbu g.gif')?'stopbu g.gif':'lbug.gi f';
}
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Thanks Randy! Now that's elegant and I've already
put it in my 'code cupboard' for future use as well.
Also thanks again to Mr. PointedEars and jshanman.
Marc Miller
a.k.a. 'Shaky Slidewell'
(ps- don't ask 8-))
JRS: In article <61************ ****@PointedEar s.de>, dated Mon, 24 Apr
2006 20:06:23 remote, seen in news:comp.lang. javascript, Thomas
'PointedEars' Lahn <Po*********@we b.de> posted :
PointedEars -- This above all: To thine own self be true. -- William Shakespeare (1564-1616)
In your case, that's bad advice.
The material after your "-- " line does not comply with FYI28/RFC1855.
Please rectify your habits.
--
© John Stockton, Surrey, UK. yyww merlyn demon co uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mike420 |
last post by:
In the context of LATEX, some Pythonista asked what the big
successes of Lisp were. I think there were at least three *big*
successes.
a. orbitz.com web site uses Lisp for algorithms, etc.
b. Yahoo store was originally written in Lisp.
c. Emacs
The issues with these will probably come up, so I might as well
mention them myself (which will also make this a more balanced
|
by: DP |
last post by:
(2nd post, I think my first may have been to the wrong group - sorry)
Hello Perl-ers -
I´m hoping I can get some help here, because I'm very lost. Don't know
Perl, I'm not a programmer. And this is something that has worked for
me earlier, only now it doesn't anymore.
---------------------------------
The ¨problem¨ script -
|
by: Robert Oschler |
last post by:
If I set window.onerror to an error handler I've created, I don't see the
browser error dialogs anymore but I don't see the alert() messages in my
error handler pop up either. Can someone tell me what I am doing wrong?
Here's the test doc I'm using:
=========== BEGIN TEST DOC ===================
<HTML>
<TITLE> OnError Test </TITLE>
<HEAD>
|
by: Carter Smith |
last post by:
http://www.icarusindie.com/Literature/ebooks/
Rather than advocating wasting money on expensive books for beginners,
here's my collection
of ebooks that have been made freely available on-line by their authors.
There are lots of them out there but this selection cuts out the junk.
If you know of any other good books that are freely available please post a
link to them here and I'll consider adding them to the site.
|
by: titan0111 |
last post by:
#include<iostream>
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;
class snowfall
{
private:
int ft;
| |
by: Nashat Wanly |
last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp
Don't Lock Type Objects!
Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad
Rico Mariani, performance architect for the Microsoft® .NET runtime
and longtime Microsoft developer, mentioned to Dr. GUI in an e-mail
conversation recently that a fairly common practice (and one that's,
unfortunately, described in some of our...
|
by: U S Contractors Offering Service A Non-profit |
last post by:
" Visionary Dreams "
" Leaving New york City leaving to go " GOD noes were
i Don't "
|
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= |
last post by:
Hello,
I have build a website with approximately 30 html-pages.
When I search this website in Google, I see the index.html or home.html on
this website, but also other html-pages on this website.
When I click in Google on one of these pages (not index.html or home.html),
I am only linked to that one html-page and not to the website itself.
Does anyone know how to fix this. Is there for example a metatag?
Thanks
|
by: Richard Maher |
last post by:
Hi,
Sorry if this is one of those issues that people feel passionate about and I
assure you I'm not trolling but rather seeking guidance on which way to go
with the web browser presentation of tabular result sets.
I'm a newbie and don't know any better, but I immediately opted for Select
Lists 'cos A) someone showed me :-) and b) 'cos I didn't think you could
select from a Table without a Button-cell on each row (but a recent post of...
|
by: Jo |
last post by:
class A {
public:
char text_a;
A() { *text_a=0; }
~A() {}
};
//-----------------------------------------------------------------------------
|
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...
| |
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...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |