onChange To Activate A Function

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

onChange To Activate A Function

Post by icesolid »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a selection box that onChange I want to have it call up the function below (this code is below my form fields but inside of my </form> tag.

[syntax="javascript"]<script language="JavaScript">
	    <!--
		function SetValues(val) {
			var boxes = document.getElementsByTagName("select");

			for(var i=0;i<boxes.length;i++) {
				if(boxes[i].name.substr(0,9) == "inspector") {
					for(var j=0;j<boxes[i].options.length;j++) {
						if(boxes[i].options[j].value == val) {
							boxes[i].selectedIndex = j;
							break;
						}
					}
				}
			}
		}
		//-->
</script>
Here is the code in my selection box:[/syntax]

Code: Select all

<select name="select_all" onchange="SetValues">

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Code: Select all

<select name="select_all" onchange="SetValues(this.value);">
Did you write that function? You weren't even giving it the variable "val"

Change `this.value` to what ever you want "val" to be.
Post Reply