Jump to content
  • Advertisement
Sign in to follow this  
ManaStone

[web] Another Javascript Question

This topic is 3376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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=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;
}



Share this post


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



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!