2009/6/27 T.J. Crowder <[email protected]>
>
> Hi,
>
> Your two examples are not identical. In the one using 'proyecto'
> literally, your if statement will always be true because you're not
> using $, you're using
>
> if('proyecto')
>
> where to be identical to the x1 version you would need
>
> if($('proyecto'))
Sorry another mistake in the mail, but again the real function is fine :P
>
>
> I don't know why that would make any difference since presumably the
> element does exist (otherwise the literal example wouldn't work), but
> it's a difference.
>
> I'd suggest you take this code:
>
> 001: document.observe('dom:loaded', function(){
> 002: var x1, elm;
> 003: x1='proyecto';
> 004:
> 005: elm = $(x1);
> 006: if (elm) {
> 007: elm.observe('change', function(evt) {
> 008: document.fire('sic:'+x1);
> 009: });
> 010: }
> 011: });
>
> And use a debugger like Firebug or similar to put a breakpoint on line
> 6 and another one on line 8, and see what you see. Is 'elm' undefined
> on line 6? Does document.fire on line 8 get called when the change
> happens?
>
Using firebug show me what elm is the correct element, but...
This are my custom events
document.observe('sic:proyecto',function(evt){
var s = evt.memo.campo_llenar || '';console.log(s);
var a = new Ajax.Updater('estado', 'carga_datos.htm', {
evalScripts: true,
parameters: {control: 'datos_proyecto',
ejercicio_id:$F('ejercicio_id')
,campo_llenar: s
,proyecto: $F('proyecto'+s)}
});
a=null;
});
document.observe('sic:material',function(evt){
var s = evt.memo.campo_llenar || '';console.log(s);
var a = new Ajax.Updater('estado', 'carga_datos.htm', {
evalScripts: true,
parameters: {control: 'datos_material',
ejercicio_id: $F('ejercicio_id')
,campo_llenar: s
,material: $F('material'+s)}
});
a=null;
});
first put only one observe (proyecto) and work fine, later add the second
observe (material), here is where the thing go crazy
Using firebug I see what when the event "change" is called by "proyecto"
this call 'sic:material' ¿uh?
document.observe('dom:loaded', function(){
var x1, elm;
x1='proyecto';
elm = $(x1);
if (elm) {
elm.observe('change', function(evt) {
document.fire('sic:'+x1);
});
}
x1='material';
elm = $(x1);
if (elm) {
elm.observe('change', function(evt) {
document.fire('sic:'+x1);
});
}
});
if change to this, work fine
var x2;
x2='material';
elm = $(x2);
if (elm) {
elm.observe('change', function(evt) {
document.fire('sic:'+x2);
});
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---