dropdown still driving me nuts...why doesnt this work

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
cardeiro
Posts: 31
Joined: March 27th, 2006, 2:03 pm
Location: philadelphia, PA
Contact:

okay I am trying to do something when a particular item is selected from the dropdown (the following is not my real code, just an example of what is going wrong).

What the code syas to me is that if 'dog' is selected an alert box will say 'yay dog' and for everything else it should alert 'boo no dog' but it says boo even when dog is selected. what am I doing wrong.



Code: Select all

var fieldWin = new Window('dialog', 'Field Init');
fieldWin.fields = fieldWin.add('panel', undefined, 'fields');
	fieldWin.fields.groupx = fieldWin.fields.add('group', undefined);
		drop = fieldWin.fields.groupx.add('dropdownlist',  undefined, ['dog', 'cat', 'fish']);
		drop.onChange = function () {
			alert(this.selection);	
			if(this.selection == 'dog'){
				alert('yay dog');
			}else{
				alert('boo no dog');
			}
		}
fieldWin.show();
Mike Cardeiro
------------------------------
Animator - Designer
D4 Creative Group
Philadelphia, PA
------------------------------
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Code: Select all

	if (this.selection.toString() == 'dog') {
You can also check this.selection.index
cardeiro
Posts: 31
Joined: March 27th, 2006, 2:03 pm
Location: philadelphia, PA
Contact:

Genius! Thanks Paul...I'd given up and resorted to an ugly hack to accomplish my task. Now I can do it right, thanks Paul.
Mike Cardeiro
------------------------------
Animator - Designer
D4 Creative Group
Philadelphia, PA
------------------------------
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

By the way, I believe this will also work:

Code: Select all

 if (this.selection.text == 'dog') {
Post Reply