PDA

View Full Version : correct value not being passed


Slapyo
11-30-2006, 05:55 PM
By default the input text says "Insert Text". I change that to "Test", hit the submit button and I get an alert saying "Insert Text". Why is it not grabbing what I change it to?

dlgCreateString.addButton('Submit', this.createString.createDelegate(this,[document.getElementById('stringText').value, document.getElementById('stringSize').value, document.getElementById('stringFont').value, document.getElementById('stringColor').value]), dlgCreateString);
createString : function(stringText, stringSize, stringFont, stringColor) {
alert(stringText);
},

jack.slocum
11-30-2006, 06:24 PM
You are passing their current value. If you want the value when the event occurs, you will need to look it up when the event occurs:

dlgCreateString.addButton('Submit', function(){
this.createString(document.getElementById('stringText').value,
document.getElementById('stringSize').value,
document.getElementById('stringFont').value,
document.getElementById('stringColor').value
);
}, this);

Slapyo
11-30-2006, 06:33 PM
That worked. Thanks. I appreciate the help. I'm still trying to wrap my head around all of this stuff and figure out how it works.

jack.slocum
11-30-2006, 06:40 PM
No problem. The callback/this stuff is probably one of the most confusing things for people getting used to OO JS.