You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Jouravlev <jm...@gmail.com> on 2006/03/11 09:34:44 UTC

[OT] Javascript in HTML events

I am cleaning up my Javascript code. First I made all functions having
prefix, so they won't mix with others' functions. Then I noticed that
DOJO uses one global variable dojo, and defines everything including
functions inside it. I thought that was cool, and tried it myself, but
it does not work.

This works:


<html>
  <head>
    <script language="javascript">
      var aaa;

      aaa = function (frm) {
        alert("Hi!");
      };
    </script>
  </head>

  <form method="post" action="qq2.html" onsubmit="return aaa (this);">
    <input type="submit" />
  </form>
</html>


This does not work (function is not called):


<html>
  <head>
    <script language="javascript">
      var aaa;

      aaa.bbb = function (frm) {
        alert("Hi!");
      };
    </script>
  </head>

  <form method="post" action="qq2.html" onsubmit="return aaa.bbb (this);">
    <input type="submit" />
  </form>
</html>


I was thinking of having one global object "aaa" and stick all my
functions inside it. Is it possible? Or HTML does not allow to call
expressions with dots in it?

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Javascript in HTML events

Posted by Michael Jouravlev <jm...@gmail.com>.
Frank, I am sorry you took time checking this. I guess, this
recommendation "Optimally, the reply should be to the thread started
by the original question posting, and should have 'FIXED', 'RESOLVED'
or an equally obvious tag in the subject line." from
http://www.catb.org/~esr/faqs/smart-questions.html does not work well
with GMail threaded messages. I will not use it anymore.

Anyway, this thing with setting content type did the trick. Amazing.
LiveHTTPHeaders still show the bizzare output, but everything works.

I am off to Barnes&Noble, will take a look at the book. If it mentions
this "bugofeature" I will buy it ;-)

Thanks again for replying!

Michael.

On 3/11/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
> Weird, I can't explain that.  I just did this as a test:
>
> <html><head><title></title>
> <script>
>    xhr = null;
>    function test() {
>      if (window.XMLHttpRequest) {
>        xhr = new XMLHttpRequest();
>      } else {
>        xhr = new ActiveXObject("Microsoft.XMLHTTP");
>      }
>      xhr.onreadystatechange = handler;
>      xhr.open("post", "test.htm", true);
>      xhr.send("p1=v1&p2=v2&p3=v3");
>    }
>    function handler() {
>      alert("handler()");
>    }
> </script>
> </head><body>
> <input type="button" onClick="test();">
> </body></html>
>
> Should be virtually identical to what your doing.  At least under IE
> using HTTPWatch, I see the parameters as POST content as expected, not
> appended to any header or anything.  For some reason LiveHTTPHeaders
> didn't even seem to want to capture for me (for all the bragging people
> do about FF, I have more trouble getting it to do what I want!).  I
> wonder if LiveHTTPHeaders is getting it wrong?  Or maybe just displaying
> some odd way that makes it look like it's a child of that header?  I
> don't know, just guessing.
>
> Oh, I see your reply about content type just now... did that solve this
> problem?  I've never had to set the content type before, and I've sent
> chunks of XML as well as plain strings and even a query string like your
> doing many times in a POST using XHR, both FF and IE, never seen any
> problem like this.
>
> Frank
>
> Michael Jouravlev wrote:
> > Thanks, Frank. I guess I need this book :) Before I get it, allow me
> > one more question.
> >
> > I have a working XHR using GET (target is full URL with query params):
> >
> >   ajaxRequest.open("GET", target, true);
> >   ajaxRequest.send(null);
> >
> > Now I want to switch to POST (url is base URL, params contain request params):
> >
> >   ajaxRequest.open("POST", url, true);
> >   ajaxRequest.send(params);
> >
> > It does not work. The parameters are sent, but apparently not as
> > content, but as "Cache-Control" attributes. The working POST request
> > shows like this in LiveHTTPHeaders (another test app):
> >
> > POST /strutsdialog/dialogloginactioncontrol.do HTTP/1.1
> > ...
> > Content-Length: 41
> > name=&password=&DIALOG-EVENT-LOGIN=Log+In
> >
> > The non-working XHR POST request looks like this:
> >
> > POST /jspcontrols-samples/login/loginComponent.jsp HTTP/1.1
> > ...
> > Content-Length: 68
> > Cache-Control: no-cache
> >     jspcontrols.ajax.xhtml=true&loginEvent=1&username=user&password=pass
> >
> > Here my parameters are listed as a child for "Cache-Control" element.
> > Application does not see them.
> >
> > What I am doing wrong and how to do it right?
> >
> > Michael
> >
> > On 3/11/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
> >> The Manning AJAX In Action book has an appendix that covers a great many
> >> of these useful techniques.  Even if you have zero interest in AJAX, I
> >> haven't seen many books or articles that covers Javascript as well as
> >> this one.  I consider myself fairly well-versed in Javascript, and even
> >> I picked up a trick or two and otherwise solidified by understanding.
> >> Very much recommended (yeah, and the coverage of AJAX ain't bad either!)
> >>
> >> Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Javascript in HTML events

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Weird, I can't explain that.  I just did this as a test:

<html><head><title></title>
<script>
   xhr = null;
   function test() {
     if (window.XMLHttpRequest) {
       xhr = new XMLHttpRequest();
     } else {
       xhr = new ActiveXObject("Microsoft.XMLHTTP");
     }
     xhr.onreadystatechange = handler;
     xhr.open("post", "test.htm", true);
     xhr.send("p1=v1&p2=v2&p3=v3");
   }
   function handler() {
     alert("handler()");
   }
</script>
</head><body>
<input type="button" onClick="test();">
</body></html>

Should be virtually identical to what your doing.  At least under IE 
using HTTPWatch, I see the parameters as POST content as expected, not 
appended to any header or anything.  For some reason LiveHTTPHeaders 
didn't even seem to want to capture for me (for all the bragging people 
do about FF, I have more trouble getting it to do what I want!).  I 
wonder if LiveHTTPHeaders is getting it wrong?  Or maybe just displaying 
some odd way that makes it look like it's a child of that header?  I 
don't know, just guessing.

Oh, I see your reply about content type just now... did that solve this 
problem?  I've never had to set the content type before, and I've sent 
chunks of XML as well as plain strings and even a query string like your 
doing many times in a POST using XHR, both FF and IE, never seen any 
problem like this.

Frank

Michael Jouravlev wrote:
> Thanks, Frank. I guess I need this book :) Before I get it, allow me
> one more question.
> 
> I have a working XHR using GET (target is full URL with query params):
> 
>   ajaxRequest.open("GET", target, true);
>   ajaxRequest.send(null);
> 
> Now I want to switch to POST (url is base URL, params contain request params):
> 
>   ajaxRequest.open("POST", url, true);
>   ajaxRequest.send(params);
> 
> It does not work. The parameters are sent, but apparently not as
> content, but as "Cache-Control" attributes. The working POST request
> shows like this in LiveHTTPHeaders (another test app):
> 
> POST /strutsdialog/dialogloginactioncontrol.do HTTP/1.1
> ...
> Content-Length: 41
> name=&password=&DIALOG-EVENT-LOGIN=Log+In
> 
> The non-working XHR POST request looks like this:
> 
> POST /jspcontrols-samples/login/loginComponent.jsp HTTP/1.1
> ...
> Content-Length: 68
> Cache-Control: no-cache
>     jspcontrols.ajax.xhtml=true&loginEvent=1&username=user&password=pass
> 
> Here my parameters are listed as a child for "Cache-Control" element.
> Application does not see them.
> 
> What I am doing wrong and how to do it right?
> 
> Michael
> 
> On 3/11/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
>> The Manning AJAX In Action book has an appendix that covers a great many
>> of these useful techniques.  Even if you have zero interest in AJAX, I
>> haven't seen many books or articles that covers Javascript as well as
>> this one.  I consider myself fairly well-versed in Javascript, and even
>> I picked up a trick or two and otherwise solidified by understanding.
>> Very much recommended (yeah, and the coverage of AJAX ain't bad either!)
>>
>> Frank
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Javascript in HTML events

Posted by Michael Jouravlev <jm...@gmail.com>.
Thanks, Frank. I guess I need this book :) Before I get it, allow me
one more question.

I have a working XHR using GET (target is full URL with query params):

  ajaxRequest.open("GET", target, true);
  ajaxRequest.send(null);

Now I want to switch to POST (url is base URL, params contain request params):

  ajaxRequest.open("POST", url, true);
  ajaxRequest.send(params);

It does not work. The parameters are sent, but apparently not as
content, but as "Cache-Control" attributes. The working POST request
shows like this in LiveHTTPHeaders (another test app):

POST /strutsdialog/dialogloginactioncontrol.do HTTP/1.1
...
Content-Length: 41
name=&password=&DIALOG-EVENT-LOGIN=Log+In

The non-working XHR POST request looks like this:

POST /jspcontrols-samples/login/loginComponent.jsp HTTP/1.1
...
Content-Length: 68
Cache-Control: no-cache
    jspcontrols.ajax.xhtml=true&loginEvent=1&username=user&password=pass

Here my parameters are listed as a child for "Cache-Control" element.
Application does not see them.

What I am doing wrong and how to do it right?

Michael

On 3/11/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
> The Manning AJAX In Action book has an appendix that covers a great many
> of these useful techniques.  Even if you have zero interest in AJAX, I
> haven't seen many books or articles that covers Javascript as well as
> this one.  I consider myself fairly well-versed in Javascript, and even
> I picked up a trick or two and otherwise solidified by understanding.
> Very much recommended (yeah, and the coverage of AJAX ain't bad either!)
>
> Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Javascript in HTML events

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
The Manning AJAX In Action book has an appendix that covers a great many 
of these useful techniques.  Even if you have zero interest in AJAX, I 
haven't seen many books or articles that covers Javascript as well as 
this one.  I consider myself fairly well-versed in Javascript, and even 
I picked up a trick or two and otherwise solidified by understanding. 
Very much recommended (yeah, and the coverage of AJAX ain't bad either!)

Frank

Craig McClanahan wrote:
> On 3/11/06, Niall Pemberton <ni...@blueyonder.co.uk> wrote:
>> Yes but you have to create an object and assign it to your "aaa" var
>> first,
>> before assigning a variable value such as "bbb"
>>
>> Try
>>       var aaa = {};
>>
>> Niall
> 
> 
> I figured out how to do this by reading the beginning of the
> dojo.js.uncompressed script, where the "dojo" object itself is set up (along
> with a couple of initial base objects inside).  Lots of useful techniques to
> learn.
> 
> Craig
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Javascript in HTML events

Posted by Michael Jouravlev <jm...@gmail.com>.
On 3/11/06, Craig McClanahan <cr...@apache.org> wrote:
> On 3/11/06, Niall Pemberton <ni...@blueyonder.co.uk> wrote:
> >
> > Yes but you have to create an object and assign it to your "aaa" var
> > first,
> > before assigning a variable value such as "bbb"
> >
> > Try
> >       var aaa = {};
> >
> > Niall
>
>
> I figured out how to do this by reading the beginning of the
> dojo.js.uncompressed script, where the "dojo" object itself is set up (along
> with a couple of initial base objects inside).  Lots of useful techniques to
> learn.

Resolved. Yo stupido, it is there indeed but I missed it. Thanks a
lot, Niall, Craig!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Javascript in HTML events

Posted by Niall Pemberton <ni...@gmail.com>.
On 3/11/06, Craig McClanahan <cr...@apache.org> wrote:
> On 3/11/06, Niall Pemberton <ni...@blueyonder.co.uk> wrote:
> >
> > Yes but you have to create an object and assign it to your "aaa" var
> > first,
> > before assigning a variable value such as "bbb"
> >
> > Try
> >       var aaa = {};
> >
> > Niall
>
>
> I figured out how to do this by reading the beginning of the
> dojo.js.uncompressed script, where the "dojo" object itself is set up (along
> with a couple of initial base objects inside).  Lots of useful techniques to
> learn.

I've been doing the same - dojo is a great place to learn.

> Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Javascript in HTML events

Posted by Craig McClanahan <cr...@apache.org>.
On 3/11/06, Niall Pemberton <ni...@blueyonder.co.uk> wrote:
>
> Yes but you have to create an object and assign it to your "aaa" var
> first,
> before assigning a variable value such as "bbb"
>
> Try
>       var aaa = {};
>
> Niall


I figured out how to do this by reading the beginning of the
dojo.js.uncompressed script, where the "dojo" object itself is set up (along
with a couple of initial base objects inside).  Lots of useful techniques to
learn.

Craig

Re: [OT] Javascript in HTML events

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Yes but you have to create an object and assign it to your "aaa" var first,
before assigning a variable value such as "bbb"

Try
      var aaa = {};

Niall

----- Original Message ----- 
From: "Michael Jouravlev" <jm...@gmail.com>
Sent: Saturday, March 11, 2006 8:34 AM


I am cleaning up my Javascript code. First I made all functions having
prefix, so they won't mix with others' functions. Then I noticed that
DOJO uses one global variable dojo, and defines everything including
functions inside it. I thought that was cool, and tried it myself, but
it does not work.

This works:


<html>
  <head>
    <script language="javascript">
      var aaa;

      aaa = function (frm) {
        alert("Hi!");
      };
    </script>
  </head>

  <form method="post" action="qq2.html" onsubmit="return aaa (this);">
    <input type="submit" />
  </form>
</html>


This does not work (function is not called):


<html>
  <head>
    <script language="javascript">
      var aaa;

      aaa.bbb = function (frm) {
        alert("Hi!");
      };
    </script>
  </head>

  <form method="post" action="qq2.html" onsubmit="return aaa.bbb (this);">
    <input type="submit" />
  </form>
</html>


I was thinking of having one global object "aaa" and stick all my
functions inside it. Is it possible? Or HTML does not allow to call
expressions with dots in it?

Michael.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org