[Javascript] Javascript Digest, Vol 18, Issue 9

shashanka n shashankan.10 at gmail.com
Fri Feb 20 01:01:09 CST 2009


On Thu, Feb 19, 2009 at 11:30 PM, <javascript-request at lists.evolt.org>wrote:

> Send Javascript mailing list submissions to
>        javascript at lists.evolt.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://lists.evolt.org/mailman/listinfo/javascript
> or, via email, send a message with subject or body 'help' to
>        javascript-request at lists.evolt.org
>
> You can reach the person managing the list at
>        javascript-owner at lists.evolt.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Javascript digest..."
>
> Today's Topics:
>
>   1.  Unobtrusive onsubmit (Terry Riegel)
>   2. Re: Unobtrusive onsubmit (J. Lester Novros II)
>   3. Re: Unobtrusive onsubmit (Peter Brunone)
>   4. Re: Unobtrusive onsubmit (J. Lester Novros II)
>   5. Re: Unobtrusive onsubmit (Terry Riegel)
>   6. Re: Unobtrusive onsubmit (J. Lester Novros II)
>   7. Re: Unobtrusive onsubmit (Paul Novitski)
>   8. Re: Unobtrusive onsubmit (Hassan Schroeder)
>   9. Re: Unobtrusive onsubmit (tedd)
>
>
> ---------- Forwarded message ----------
> From: Terry Riegel <riegel at clearimageonline.com>
> To: JavaScript List <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 14:03:09 -0500
> Subject: [Javascript] Unobtrusive onsubmit
> I am working through an unobtrusive bit of javascript and wonder if anyone
> might be able to lend a hand.
>
>  <FORM ACTION="../cgi-bin/mycgi.pl" ID="testform" NAME="testform"
> onSubmit="return TestDataCheck()">
>
> I would like to take this onSubmit out of the form declaration and put it
> in an startup function that runs on load.
>
> So I have this...
> document.getElementById('testform').onsubmit=TestDataCheck;
> I am not sure of the syntax that would duplicate the return part of the
> obtrusive JS.
> I have tried this...
> document.getElementById('testform').onsubmit=return TestDataCheck;
>
> How would I get it to invalidate the action of the form and just do
> something else?
>
> Any help will be greatly appreciated.
>
> Terry Riegel
>
>
>
> ---------- Forwarded message ----------
> From: "J. Lester Novros II" <lester at denhaag.org>
> To: JavaScript List <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 20:24:33 +0100
> Subject: Re: [Javascript] Unobtrusive onsubmit
> Terry,
>
> Terry Riegel wrote:
>
>> So I have this...
>> document.getElementById('testform').onsubmit=TestDataCheck;
>>
>
> Not quite to the point but be aware that IE does not differ between 'name'
> and 'id' namespaces so this will have consequences for your script.
>
> Just a heads up.
>
> l8R lES
> --
> Microsoft's business practices have fundamentally diminished (in fact,
> came very close to eliminating) competition, choice and innovation in
> how people access the Internet.        Mitchell Baker - Mozilla Chair
>                 http://www.supermarionation.tv
>
>
>
> ---------- Forwarded message ----------
> From: "Peter Brunone" <peter at brunone.com>
> To: "JavaScript List" <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 12:32:04 -0700
> Subject: Re: [Javascript] Unobtrusive onsubmit
> > IE does not differ between 'name'
> > and 'id' namespaces
>
> What exactly does that mean?
>
> ----------------------------------------
>
> From: "J. Lester Novros II" <lester at denhaag.org>
>
> Terry,
>
> Terry Riegel wrote:
> > So I have this...
> > document.getElementById('testform').onsubmit=TestDataCheck;
>
> Not quite to the point but be aware that IE does not differ between 'name'
>
> and 'id' namespaces so this will have consequences for your script.
>
> Just a heads up.
>
> l8R lES
>
>
>
> ---------- Forwarded message ----------
> From: "J. Lester Novros II" <lester at denhaag.org>
> To: JavaScript List <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 20:43:31 +0100
> Subject: Re: [Javascript] Unobtrusive onsubmit
> Peter Brunone wrote:
>
>> IE does not differ between 'name' and 'id' namespaces
>>>
>>
>> What exactly does that mean?
>>
>
> It means that IE will *always* return the element with the corresponding
> name rather than the element with the desired id if there are two elements,
> one with an 'id' and another with a 'name' that are identical.
>
> I don't really know what happens when one element has an identical id and
> name but I thought to better bring this up than have the script author get
> mired in difficult to trace bugs/unwanted script behaviour.
>
> Also, this came up on the list quite a while ago. Maybe the archives can be
> searched for the 'namespace' search term.
>
> l8R lES
> --
> Microsoft's business practices have fundamentally diminished (in fact,
> came very close to eliminating) competition, choice and innovation in
> how people access the Internet.        Mitchell Baker - Mozilla Chair
>                 http://www.supermarionation.tv
>
>
>
> ---------- Forwarded message ----------
> From: Terry Riegel <riegel at clearimageonline.com>
> To: JavaScript List <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 14:48:52 -0500
> Subject: Re: [Javascript] Unobtrusive onsubmit
>
>> So I have this...
>>> document.getElementById('testform').onsubmit=TestDataCheck;
>>>
>>
>> Not quite to the point but be aware that IE does not differ between 'name'
>> and 'id' namespaces so this will have consequences for your script.
>>
>
> I am actually using prototype with the dollar function.
>
>
>
> ---------- Forwarded message ----------
> From: "J. Lester Novros II" <lester at denhaag.org>
> To: JavaScript List <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 21:01:44 +0100
> Subject: Re: [Javascript] Unobtrusive onsubmit
> Terry Riegel wrote:
>
>> I am actually using prototype with the dollar function.
>>
>
> I am not too familiar with that library and syntax, maybe it abstracts away
> this particular bug.
>
> I just thought I give you the heads up since it once took me hours to
> figure out why my script wasn't working properly and it turned out to be
> this stupid IE bug.
>
> l8R lES
> --
> Microsoft's business practices have fundamentally diminished (in fact,
> came very close to eliminating) competition, choice and innovation in
> how people access the Internet.        Mitchell Baker - Mozilla Chair
>                 http://www.supermarionation.tv
>
>
>
> ---------- Forwarded message ----------
> From: Paul Novitski <paul at juniperwebcraft.com>
> To: JavaScript List <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 12:07:25 -0800
> Subject: Re: [Javascript] Unobtrusive onsubmit
> Hey Terry,
>
> At 2/18/2009 11:03 AM, Terry Riegel wrote:
>
>> I am working through an unobtrusive bit of javascript and wonder if
>> anyone might be able to lend a hand.
>>
>>  <FORM ACTION="../cgi-bin/mycgi.pl" ID="testform" NAME="testform"
>> onSubmit="return TestDataCheck()">
>>
>> I would like to take this onSubmit out of the form declaration and put
>> it in an startup function that runs on load.
>>
>> So I have this...
>> document.getElementById('testform').onsubmit=TestDataCheck;
>> I am not sure of the syntax that would duplicate the return part of
>> the obtrusive JS.
>> I have tried this...
>> document.getElementById('testform').onsubmit=return TestDataCheck;
>>
>> How would I get it to invalidate the action of the form and just do
>> something else?
>>
>
>
> The short answer is that if the javascript function triggered by onSubmit
> returns FALSE, the form won't submit.
>
> Here's one way to do it (below).  This code won't crash if it's run in a
> browser that doesn't support DOM-aware javascript nor if the 'testform'
> object isn't found.
>
> And of course it should go without saying that since you can't trust that
> javasrcipt will be present to test your form data you need to do it again
> server-side.
>
> Paul
> _______________________
>
>
> HTML:
> <form action="../cgi-bin/mycgi.pl" id="testform" ...>
>
>
> JavaScript:
>
> // tell js to initialize the form when the page loads
> AddEvent(window, "load", FormInit);
>
>
> //=========================
> function FormInit()
> //=========================
> // intialize the form
> {
>                // go away if DOM not supported
>                if (!document.getElementById) return;
>
>        // apply onsubmit behavior to form object
>        oForm = document.getElementById('testform');
>
>                if (oForm)
>                {
>                        AddEvent(oForm, "submit", TestDataCheck);
>                }
> }
>
>
> //=========================
> function TestDataCheck(evt)
> //=========================
> // test the data when the form is submitted
> {
>        // cancel event-bubbling
>                if (evt) { event = evt; }
>        event.cancelBubble = true;
>
>        // test the data...
>        bSuccess = ValidateForm();
>
>                // display error messages as needed
>                if (!bSuccess)
>                {
>                        ...
>                }
>
>        // if checks failed return FALSE to cancel form submission
>        // if checks are OK return TRUE to allow form submission
>        return bSuccess;
> }
>
>
> //=========================
> function AddEvent(oElement, sEventName, fnFunction)
> //=========================
> // add an event to the DOM
> {
>        if (oElement)
>        {
>                if (oElement.attachEvent)
>                {
>                        oElement.attachEvent("on" + sEventName, fnFunction);
>                }
>                else
>                {
>                        oElement.addEventListener(sEventName, fnFunction,
> true);
>                }
>        }
> }
>
>
>
>
> ---------- Forwarded message ----------
> From: Hassan Schroeder <hassan at webtuitive.com>
> To: JavaScript List <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 11:59:22 -0800
> Subject: Re: [Javascript] Unobtrusive onsubmit
> Terry Riegel wrote:
>
>  I am actually using prototype with the dollar function.
>>
>
> In that case, you can use Event.stop(ev) -- see the documentation
> (and the source) for more info.
>
> --
> Hassan Schroeder ----------------------------- hassan at webtuitive.com
> Webtuitive Design ===  (+1) 408-621-3445   === http://webtuitive.com
>
>                          dream.  code.
>
>
>
> ---------- Forwarded message ----------
> From: tedd <tedd at sperling.com>
> To: JavaScript List <javascript at lists.evolt.org>
> Date: Wed, 18 Feb 2009 15:58:51 -0500
> Subject: Re: [Javascript] Unobtrusive onsubmit
> At 2:03 PM -0500 2/18/09, Terry Riegel wrote:
>
>> I am working through an unobtrusive bit of javascript and wonder if anyone
>> might be able to lend a hand.
>>
>>  <FORM ACTION="../cgi-bin/mycgi.pl" ID="testform" NAME="testform"
>> onSubmit="return TestDataCheck()">
>>
>> I would like to take this onSubmit out of the form declaration and put it
>> in an startup function that runs on load.
>>
>> So I have this...
>> document.getElementById('testform').onsubmit=TestDataCheck;
>> I am not sure of the syntax that would duplicate the return part of the
>> obtrusive JS.
>> I have tried this...
>> document.getElementById('testform').onsubmit=return TestDataCheck;
>>
>> How would I get it to invalidate the action of the form and just do
>> something else?
>>
>> Any help will be greatly appreciated.
>>
>> Terry Riegel
>>
>
> Terry:
>
> Here's an example that works as you want:
>
> http://www.webbytedd.com/ccc/uob-onsubmit-oneform/index.php
>
> The form simply has a name, in this case 'a'. Besides the javascript being
> loaded via the head, there is no other javascript within the page (except
> the where it shows the code, but that's for demo only).
>
> As is typical, when the pages loads, the javascript is loaded. However, the
> js script monitors what the html is doing and when the user clicks "submit",
> javascript takes over and asks for both fields to be filled. BUT please note
> -- no javascript hooks (i.e., onClick, onSubmit) appears within the html,
> thus it is Unobtrusive. Kind on neat, huh? :-)
>
> HTH's
>
> tedd
>
> --
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
>

I am using something like this for the desired functionality :

In HTML:<body onLoad="Pageload"> or

In JS : document.body.onload=Pageload  at the end of your document

then,

ThisClass.Pageload=function()
{
       //Stuff to do when the pageload happens...
}

-- 
- Warm regards

Shashanka N



More information about the Javascript mailing list