[web] Another Javascript Question

Started by
1 comment, last by ManaStone 14 years, 7 months ago
Is there a way I can set an html event so that it responds to a specific &#106avascript object method? For example, look at the "onchange" part of my CreateHtml method.

function MyObject()
{

	//Array of Selects
	var mDropLists;
	var mNumDropLists;
	
	function SetNumSelects(argNum)
	{
		mNumDropLists=argNum;
		
		mDropLists = new Arrary(argNum);
	}
	function AddOption(argIndex argValue,argText)
	{	
		//Create Option
		var myOption = document.createElement("option");
		myOption.text = argText;
		myOption.value = argValue;
		
		//Adds Option to a select object from mDropLists Array with index argIndex 
		mDropLists[argIndex].appendChild(myOption);
		
	}
	function CreateHtml()
	{
		//Create Select Objects
		for(i=0; i<mNumDropLists;i++)
		{
			var SelName="'Sel"+i+"'";
			document.write("<select name ="+SelName);
			document.write(" id ="+SelName);
			
			//How do I make something like this work?
			document.write(" onchange='EnableNextSelect("+i+")'");
			
			document.write("</select>");
			
			mDropLists=document.getElementById(SelName);
			mDropLists.disabled=true;
		}
		
		//enable first select
		mDropLists[0].disabled=false;
	}

	function EnableNextSelect(argIndex)
	{
		if(argIndex<mNumDropLists)
		{
			//Disable Current Select
			mDropLists[argIndex].disabled=true;
		
			//Enable Next Select
			mDropLists[argIndex+1].disabled=false;
		}
	}
	

	this.CreateHtml=CreateHtml;
}



-----------------------------Download my real time 3D RPG.
Advertisement
If you have used the suggestion in my previous post, you can set a message handler like so:

function EnableNextSelect(){  alert("Value changed to " + this.value);}var mySelect = document.createElement("select");mySelect.onchange = EnableNextSelect;
Thanks wan.
-----------------------------Download my real time 3D RPG.

This topic is closed to new replies.

Advertisement