Sign in to follow this  
ManaStone

[web] Another Javascript Question

Recommended Posts

Is there a way I can set an html event so that it responds to a specific javascript 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[i]=document.getElementById(SelName);
			mDropLists[i].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;
}



Share this post


Link to post
Share on other sites
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;



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this