![]() |
|
|
#1
|
|||
|
|||
|
little help with switch case staement
hi the user can change a selected image by choosing an option from a menu ive got that complete but what i want to do now is when the user clicks that image something happens for each different image i am trying to use the following code to do this but its giving me problems throwing me errors. is it way off or just need a wee bit of tweaking?
Code:
<img border="2" src="Buchaille_Etive_Mor.jpg" name="bigpic" align="top" width="120" height="90"
onclick ="
picture = (bigpic.src)
<SCRIPT LANGUAGE="JavaScript">
switch (picture)
{
case "aonach_egach.jpg":
alert("still")
break;
default :
alert("still 2")
}
</SCRIPT>
">
thanks |
|
#2
|
|||
|
|||
|
You should do something like this:
HTML: Code:
<img [...] onclick="imageSwitch(this.src)" /> Code:
<script type="text/javascript">
<!--
function imageSwitch(src)
{
// switch statement goes here
}
// -->
</script>
__________________
SEO Tool - The killer search engine optimization tool. No. Really. The Search Engine Experiment - Discover if Google really giving you the most relevant results - No recip required. |
|
#3
|
|||
|
|||
|
hi thnaks for your reply i have changed it to what you said
Code:
<img border="2" src="Buchaille_Etive_Mor.jpg" name="bigpic" align="top" width="120" height="90" onclick="imageSwitch(bigpic.src)">
<script type="text/javascript">
<!--
function imageSwitch(src)
{
case "aonach_egach.jpg":
alert("still")
break;
default :
alert("still 2")
}
// -->
</script>
|
|
#4
|
|||
|
|||
|
You had a few errors, try this revision:
Code:
<img border="2" src="Buchaille_Etive_Mor.jpg" name="bigpic" align="top" width="120" height="90" onclick="imageSwitch(this.src)">
<script type="text/javascript">
<!--
function imageSwitch(src)
{
switch(src)
{
case "aonach_egach.jpg":
alert("still");
break;
default:
alert("still 2");
}
}
// -->
</script>
__________________
SEO Tool - The killer search engine optimization tool. No. Really. The Search Engine Experiment - Discover if Google really giving you the most relevant results - No recip required. |
|
#5
|
|||
|
|||
|
ahhh thanks (complete nooby if you hadnt worked that out)
cheers again |
|
#6
|
|||
|
|||
|
hmmm actually one more question it now seems to always be saying the case else statment "still 2" all the time even if the right image is showing i know the filename aonach_egach.jpg is definiatley correct
in your code where it says (this.src) i put in my name of my image "bigpic" in there yeh ? so itll be (bigpic.src) thats still giving the problem above but just wondered if that should be done anyway? thanks for you time Last edited by fraser5002; Mar 27th 2005 at 3:03 pm. |
|
#7
|
|||
|
|||
|
Quote:
J.D. |
|
#8
|
|||
|
|||
|
it does work but theres just one small problem it always goes to the default option of the switch statement but i dont know why as the case statements im giving the function are definetly correct.
ive tried it with lots of different images all doing the same thing. |
|
#9
|
|||
|
|||
|
Quote:
function imageSwitch(src) { alert(src); switch(src) ... I would change this code to use name/ID instead. J.D. |
|
#10
|
|||
|
|||
|
thanks for the advice i see what you mean now but the way i have set it up so that when the user changes the image the picture has the same name just a different src if you know what i mean?
like user clicks a hyperlink bigpic.src = "blabla" so i dont think i can use youe method of passing out the image name ( mayby im on the wrong end of the stick ) i know in VB you can strip off part of a filename just to reveal the last part something.jpg can this be done in Javascript? sorry if my terminology is way off |
|
#11
|
|||
|
|||
|
Quote:
src = src.replace(new RegExp("^.*/([^\\.]+\\.[a-z]+)$", "i"), "$1"); J.D. |
|
#12
|
|||
|
|||
|
thanks for your help
Quote:
dont have a scooby what it means but does the job.
|
|
#13
|
|||
|
|||
|
Quote:
Code:
^ : start at the beginning of the line .* : zero or more (*) occurrences of any character (.) / : (/) ( : begin a group that may be later references by $1 [^\\.]+ : one or more (+) occurence of any character except (.) \\. : escaped (.) [a-z]+ : one or more (+) characters from (a) to (z) ) : end of the group $ : end of the line J.D. |
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| switch ur hotmail into 250 mb | mohamad1983 | General Chat | 13 | Jan 22nd 2008 4:35 pm |
| About Switch Statement (php) | Nasimov | PHP | 11 | Oct 27th 2005 2:18 pm |
| Google and the Mysterious Case of the 1969 Pagejackers | vagrant | 25 | Feb 15th 2005 10:37 am | |
| Micro-SaP's threat, switch to XP or? | anthonycea | General Chat | 10 | Sep 27th 2004 5:02 pm |
| Are SE's case sensitive to meta tags? | harish318 | Search Engine Optimization | 2 | Jun 26th 2004 12:05 am |