[mochikit] getNodeAttribute Fails in an OnFocus Handler - Final Post Attempt

2007-05-22 Thread mcravitz
Please excuse me. I attempted to post this twice before, but I now realize I 
must do it from the email address in which I registered. Anyway, my problem is 
that I don't believe that an onfocus handler can rely on getNodeAttribute to 
retrieve the contents of another node. I created a small example of this (see 
below). In my example, I have two text fields named text1 and text2 which I 
believe are remarkably original names :). I attach an onfocus handler to text2 
whose job is to display the content of text1 in an alert message. It uses 
getNodeAttribute to attempt to retrieve the contents of text1, but this fails. 
Instead getNodeAttribute returns null. On the other hand if I use the less 
desirable instruction textVal = TheForm.text1.value; it works correctly. So I 
don't need a workaround, I just want to understand why getNodeAttribute fails 
to retrieve the value in this case. My preference is to use MochiKit functions 
wherever possible. Thanks in advance.

Mike

html xmlns=http://www.w3.org/1999/xhtml; xmlns:py=http://purl.org/kid/ns#;
script src=MochiKit.js type=text/javascript
/script
script type=text/javascript
 function displayText1(e)
  {
  //Note if I substitute for the following line the following
  //this script will work properly.
  //textVal = document.TheForm.text1.value;
  text1Val = getNodeAttribute(document.TheForm.text1, 'value');
  alert('Text1 contains ' + text1Val);
  }
connect(self, 'onload', function(e)
  {
  connect(TheForm.text2, 'onfocus', displayText1);
  }
);
/script
body
 form name=TheForm
 input type=text name=text1 \
 input type=text name=text2 \
 /form
/body
/html
html xmlns=http://www.w3.org/1999/xhtml; xmlns:py=http://purl.org/kid/ns#;
script src=MochiKit.js type=text/javascript
/script
script type=text/javascript
 function displayText1(e)
  {
  //Note if I substitute for the following line the following
  //this script will work properly.
  //textVal = document.TheForm.text1.value;
  text1Val = getNodeAttribute(document.TheForm.text1, 'value');
  alert('Text1 contains ' + text1Val);
  }
connect(self, 'onload', function(e)
  {
  connect(TheForm.text2, 'onfocus', displayText1);
  }
);
/script
body
 form name=TheForm
 input type=text name=text1 \
 input type=text name=text2 \
 /form
/body
/html
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: getNodeAttribute Doesn't Work In An OnFocus Handler

2007-05-22 Thread Bob Ippolito

On 5/22/07, MikeC [EMAIL PROTECTED] wrote:

 It seems that I am being forced to not use getNodeAttribute in one
 instance. I created a small example (see below) of where it seems to
 fail. My little example contains two text boxes. You enter some text
 in the first one and the onfocus handler for the second text box will
 show you (via an alert function) the content of the first box. The
 problem is that it doesn't work using MochiKit's getNodeAttribute. But
 it does work using the less desirable construct...

 text1Val = document.TheForm.text1.value;

 Thanks for any explanation of why this is the case.

I'm not entirely sure why it doesn't work.. but it's probably because
you're going through the ancient form API rather than the DOM API.

I don't see any real reason to prefer getNodeAttribute for value in
this case. Do you like it because it's slower and less direct?  ;)

-bob

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---