Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using dojo but an object question

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hey all, I have an object question for you. I have created this object to dynamically create a dojo widget (dijit) and I need to change the onChange Part.
Code:
var wdgt = {
							//----------------------------------------------------------------------------------------------------------------------------------------
							//	txtValidation
							//		This will validate data that is contained within a textbox
							//			newDivId	= This is the name of the new div id
							//			putDivId	= This is the name of the div id that we are going to put this html object
							//			maxLen		= This is the length that the input box will allow
							//			regEp		= This is the regular expresion that must happen before any of the data will be processes
							//			pCase		= This is if propercse (meaning the first letter is uppercase) true for yes or blank for no
							//			errMsg		= This is the error message if the data does not meet the regular expression
							//----------------------------------------------------------------------------------------------------------------------------------------
							txtValidation : function (newDivId,putDivId,maxLen,regEp,pCase,errMsg){
		                        var textArea = new dijit.form.ValidationTextBox({
		                                            'id':newDivId,
													'class':'medium',
	
													'name':newDivId,
													'required':"true",
													'maxlength':maxLen,
													 'trim':'true',
													'regExp':regEp,
													'propercase':pCase,
			                                        'onChange': function(){ wasChanged(newDivId);},       
		    	                                    'invalidMessage':errMsg
		                         },document.createElement("div"));
								dojo.byId(putDivId).appendChild(textArea.domNode);
							}
				}
as you see I have hard coded the 'onChange': function(){ wasChanged(newDivId);}, in the wrapper. I would like to pass a new function location like goHere(newDivId). How do I do that? DO I have go add goHere(newDivId) into a new object and pass that object to the wdge.txtValidation? I know that I am using dojo but this is a Javascript question.

Thanks,
timgerr

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Hi,
you can probobly do something like
Code:
'onChange': function(){ wasChanged(newDivId); goHere(newDivId);},
define your function somewhere else. either make it global
Code:
function goHere(){
	alert(goHere);
}
or
Code:
goHere: function(){alert(goHere)},
'onChange': function(){ wasChanged(newDivId);},
I havn't worked with dojo yet but thats how I would approach it.
 
OK here is what I want to do, I have an object that I want to pass information into
Code:
function happy(place)
{
  var test = new Object();
  test[Change] = function(){ place(newDivId)};
}
happy(here);
This will not work, how can I change the test[Change] = function(){ place(newDivId)}; by passing information into happy(place)?

Thanks,
timgerr

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
don't exactly understand. Take the example below and paste it into a text file and save it as html.
I would make sure to name your objects and methods very descriptively when working with bigger objects cause
it can get confusing.Your happy function would make a new Object test? and then the test Object has a method change?
and your defining change to call a function place?

Code:
<HTML>
<script type = "text/JavaScript">
//this would be your test obj, i think
function happyObj(place){
	this.placeVar = place;
}
//this would replace your methond change
happyObj.prototype.setPlaceMethod = function(){
	   document.getElementById('somePlace').innerHTML= this.placeVar;
}

function makeHappy(id){
		var myHappy=new happyObj(id);
		myHappy.setPlaceMethod();
		alert('myHappy.placeVar = "' + myHappy.placeVar+'"');
}
</script>
<body>
	<div stlye="border:solid 1px red;" id="somePlace">somePlace</div>
	<input type="Text" id="somePlaceDescription" value="somePlace">
	<button type="button" onclick="makeHappy(document.getElementById('somePlaceDescription').value)">test</button>
</body>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top