I'm missing something obvious I'm sure

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
SpiderMonkey
Forum Commoner
Posts: 85
Joined: Fri May 05, 2006 4:48 am

I'm missing something obvious I'm sure

Post by SpiderMonkey »

I have this element, inside form tags:

Code: Select all

<select name="List1" size=9 onchange="colourChange()" id="colour">
		<option value="0" selected><select a colour></option>
		<option value="1">Antiquated Blue</option>
		<option value="2">Antiquated Brown</option>
	            ....
		</select>
To use this function:

Code: Select all

<script type="text/javascript">
function colourChange() {
  alert("TEST");
  select (document.colour.value) {
    case 1:
      document.cs.src="Resources/antblue.jpeg";
      break
    case 2:
      document.cs.src="Resources/antbrown.jpeg";
      break
    case 3:
      document.cs.src="Resources/antburgundy.jpeg";
      break
    case 4:
      document.cs.src="Resources/antgreen.jpeg";
      break
    case 5:
      document.cs.src="Resources/antmustard.jpeg";
      break
    case 6:
      document.cs.src="Resources/antolive.jpeg";
      break
    case 7:
      document.cs.src="Resources/antred.jpeg";
      break
    case 8:
      document.cs.src="Resources/anttan.jpeg";
      break
    case 9:
      document.cs.src="Resources/antvanilla.jpeg";
      break
    case 10:
      document.cs.src="Resources/plainblack.jpeg";
      break
    case 11:
      document.cs.src="Resources/plainblue.jpeg";
      break
    case 12:
      document.cs.src="Resources/plainbrown.jpeg";
      break
    case 13:
      document.cs.src="Resources/plainburgundy.jpeg";
      break
    case 14:
      document.cs.src="Resources/plaingreen.jpeg";
      break
    case 15:
      document.cs.src="Resources/plainmustard.jpeg";
      break
    case 16:
      document.cs.src="Resources/plainolive.jpeg";
      break
    case 17:
      document.cs.src="Resources/plainred.jpeg";
      break
    case 18:
      document.cs.src="Resources/plainvanilla.jpeg";
      break
    default:
      document.cs.src="Resources/plainblack.jpeg";
      break
  }
}
</script>
But it won't run it (thats why the alert is there)

I know I've made some elementary mistake but I can't for the life of my spot it. Probably because I've not had breakfast this morning.
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

Post by asgerhallas »

hi...

yeah you're missing two thing as far as I can tell...

1. there's no such thing as a select() statement, it's a switch(var) {}
2. I guess it's a good idea to end the breaks with ;

/Asger
SpiderMonkey
Forum Commoner
Posts: 85
Joined: Fri May 05, 2006 4:48 am

Post by SpiderMonkey »

asgerhallas wrote:hi...

yeah you're missing two thing as far as I can tell...

1. there's no such thing as a select() statement, it's a switch(var) {}
2. I guess it's a good idea to end the breaks with ;

/Asger
You're right. I keep getting my languages confused.

Regardless, it isn't even getting that far, given that the alert box never appears.

EDIT: That seems to have got it actually, thanks. I guess this highlights the important of fibre.
Last edited by SpiderMonkey on Fri Jun 02, 2006 5:48 am, edited 1 time in total.
asgerhallas
Forum Commoner
Posts: 80
Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark

Post by asgerhallas »

In javascript the function isn't even created if it contains errors... so yes, when you solve those issues, the alert box will come up.

Javascript debugging is a science in it self :)

EDIT: the function is created, but it isn't called. All execution of JS stops when an error is encountered in IE - but IE does not always (and I still don't understand why) evoke an error message, if the error is contained in a function.

/Asger
Post Reply