[jQuery] Re: event.preventDefault() seems to fail

2008-11-03 Thread Prajwala Manchikatla
I just changed input button type from submit to button. Then it is working
as your need. The submit button will always call the form submit when ever
it is clicked, even when you press enter also it call the form submit. But
normal button do not call form submit all the time.
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>
   
   Test
   
   
 $(function() {
   $(":text").keypress(function(e) {
 if (e.which == 13) {
   e.preventDefault();
 }
   });
   $("#txt").keypress(function(e) {
 if (e.which == 13) {
   $("#btn").click();
 }
   });
   $("#btn").click(function(e) {
 e.preventDefault();
 alert("Button clicked");
   });
 });
   
   
   
 
   
 
 
   
 
   



On Mon, Nov 3, 2008 at 7:17 AM, Hullah <[EMAIL PROTECTED]> wrote:

>
> Ok, I see what you're saying now.  But stopPropigation doesn't work in
> this case either.  Looking at the code sample that I posted at the
> beginning, even if I add a e.stopPropagation() after the
> preventDefault() it still causes the form to submit.


[jQuery] Re: event.preventDefault() seems to fail

2008-11-02 Thread Hullah

Ok, I see what you're saying now.  But stopPropigation doesn't work in
this case either.  Looking at the code sample that I posted at the
beginning, even if I add a e.stopPropagation() after the
preventDefault() it still causes the form to submit.


[jQuery] Re: event.preventDefault() seems to fail

2008-10-30 Thread Prajwala Manchikatla
Sorry for late reply.

It is like this, suppose if you have  elements like this

  I am parent
  
   I am child
  


If you assign onclick event for both parent and child. when you click on
parent div then parent div event handlers will fire. when you click on child
div then first child div event handlers will fire and then parent div event
handler will fire.
When you use "event.stopPropagation()" in the child event handler then it
does not go to parent event handler.
When you specify event.preventDefault() you are just stoping browser default
action for that event but not stoping propagation to parent div.
To stop propagation to parent element use stopPropagation function.

cheers,
Prajwala

On Sat, Oct 25, 2008 at 7:57 AM, Hullah <[EMAIL PROTECTED]> wrote:

>
> I'm sorry, but I'm not following you.  Can you further explain what
> you mean?
>
> Thanks
>
> On Oct 24, 12:36 am, "Prajwala Manchikatla" <[EMAIL PROTECTED]>
> wrote:
> > You can think of stopPropagation.
> http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-flow
> > I hope this might help you.
>


[jQuery] Re: event.preventDefault() seems to fail

2008-10-24 Thread Hullah

I'm sorry, but I'm not following you.  Can you further explain what
you mean?

Thanks

On Oct 24, 12:36 am, "Prajwala Manchikatla" <[EMAIL PROTECTED]>
wrote:
> You can think of 
> stopPropagation.http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-flow
> I hope this might help you.


[jQuery] Re: event.preventDefault() seems to fail

2008-10-23 Thread Prajwala Manchikatla
You can think of stopPropagation.
http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-flow
I hope this might help you.
On Sat, Oct 18, 2008 at 11:26 PM, Ryan Hullah <[EMAIL PROTECTED]> wrote:

>
> I've thought of that, but I'm not sure that would work for me.  I only
> want a sub section of input textboxes and certain input buttons within
> that sub section to prevent the form submit on the Enter button.  So
> if I did it on the form submit event, I'd need to know who caused the
> submit and whether or not to cancel it.  My sample was simpler that my
> real world form for the purpose of the question.  If it's not as hard
> as I'm thinking it is, please explain.
>
> On Sat, Oct 18, 2008 at 6:08 AM, Prajwala Manchikatla
> <[EMAIL PROTECTED]> wrote:
> > instead of using preventDefault for the input, submit buttons use it for
> the form.submit event. That means write a event handler for onsubmit event
> of form and in that handler use preventDefault. It will work. We also had a
> same requirement. It solves the problem.
>


[jQuery] Re: event.preventDefault() seems to fail

2008-10-18 Thread Ryan Hullah

I've thought of that, but I'm not sure that would work for me.  I only
want a sub section of input textboxes and certain input buttons within
that sub section to prevent the form submit on the Enter button.  So
if I did it on the form submit event, I'd need to know who caused the
submit and whether or not to cancel it.  My sample was simpler that my
real world form for the purpose of the question.  If it's not as hard
as I'm thinking it is, please explain.

On Sat, Oct 18, 2008 at 6:08 AM, Prajwala Manchikatla
<[EMAIL PROTECTED]> wrote:
> instead of using preventDefault for the input, submit buttons use it for the 
> form.submit event. That means write a event handler for onsubmit event of 
> form and in that handler use preventDefault. It will work. We also had a same 
> requirement. It solves the problem.


[jQuery] Re: event.preventDefault() seems to fail

2008-10-18 Thread Prajwala Manchikatla
instead of using preventDefault for the input, submit buttons use it for the
form.submit event. That means write a event handler for onsubmit event of
form and in that handler use preventDefault. It will work. We also had a
same requirement. It solves the problem.

On Sat, Oct 18, 2008 at 9:14 AM, Hullah <[EMAIL PROTECTED]> wrote:

>
> Hmm...it looks like triggerHandler() is what I want.  Because my goal
> is to not submit the form, which was the reason I was calling
> event.preventDefault() inside the click event.
>
> I just thought it was confusing because in the click even of the
> button I was trying to prevent the default action of submitting the
> form by calling preventDefault, yet the form was still submitting.
>
> Thanks for pointing out triggerHandler.
>
> On Oct 17, 8:24 pm, Choan Gálvez <[EMAIL PROTECTED]> wrote:
> > While I don't fully understand what you want to do, I suspect that
> > what you need is the `triggerHandler` method. See <
> http://docs.jquery.com/Events/triggerHandler
> >  >.
> >
> > Or... submit the form instead of clicking the button.
>


[jQuery] Re: event.preventDefault() seems to fail

2008-10-17 Thread Hullah

Hmm...it looks like triggerHandler() is what I want.  Because my goal
is to not submit the form, which was the reason I was calling
event.preventDefault() inside the click event.

I just thought it was confusing because in the click even of the
button I was trying to prevent the default action of submitting the
form by calling preventDefault, yet the form was still submitting.

Thanks for pointing out triggerHandler.

On Oct 17, 8:24 pm, Choan Gálvez <[EMAIL PROTECTED]> wrote:
> While I don't fully understand what you want to do, I suspect that  
> what you need is the `triggerHandler` method. See 
>   >.
>
> Or... submit the form instead of clicking the button.


[jQuery] Re: event.preventDefault() seems to fail

2008-10-17 Thread Choan Gálvez


On Oct 17, 2008, at 11:22 PM, Hullah wrote:



I would think preventDefault() is the right way to do it too.

So, given that this isn't working like I would have thought it should,
did I code this incorrectly? Or is this something more serious like a
bug?


While I don't fully understand what you want to do, I suspect that  
what you need is the `triggerHandler` method. See .


Or... submit the form instead of clicking the button.






On Oct 17, 4:36 pm, Choan Gálvez <[EMAIL PROTECTED]> wrote:

On Oct 17, 2008, at 7:37 PM, ricardobeat wrote:



It should work... but in jQuery 'return false' is the standard  
cross-

browser way of preventing the default action anyway,


Not exactly.

- `preventDefault()` **is** the cross-browser way of preventing the
default action.

- `return false` prevents the default action and stops the event
propagation.




On Oct 16, 11:16 pm, Hullah <[EMAIL PROTECTED]> wrote:
I have a page with input textboxes and input buttons on it.  All  
are

contained in a form.  I don't want the Enter button to submit the
form, so I call preventDefault() on all texboxes.  I also don't  
want

the input button to submit the form, so I call preventDefault() on
the
input button.



But, if I call the button.click() event for when Enter is pressed
in a
textbox (to simulate a click on the button) it submits the form.   
It

seems as if something is not working like it should.


Now...if I "return false" instead of preventDefault(), it works  
as I

would expect.  But I would have thought that the purpose of
preventDefault() is to cancel the default action of the event, as  
in

this case to cancel form submission.


Any help with this is greatly appreciated!  Following is some  
sample

code that exhibts the behavoir.



Thanks,
Hullah



http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>

Test


  $(function() {
$(":text").keypress(function(e) {
  if (e.which == 13) {
e.preventDefault();
  }
});
$("#txt").keypress(function(e) {
  if (e.which == 13) {
$("#btn").click();
  }
});
$("#btn").click(function(e) {
  e.preventDefault();
  alert("Button clicked");
});
  });



  

  
  

  









[jQuery] Re: event.preventDefault() seems to fail

2008-10-17 Thread Hullah

I would think preventDefault() is the right way to do it too.

So, given that this isn't working like I would have thought it should,
did I code this incorrectly? Or is this something more serious like a
bug?

On Oct 17, 4:36 pm, Choan Gálvez <[EMAIL PROTECTED]> wrote:
> On Oct 17, 2008, at 7:37 PM, ricardobeat wrote:
>
>
>
> > It should work... but in jQuery 'return false' is the standard cross-
> > browser way of preventing the default action anyway,
>
> Not exactly.
>
> - `preventDefault()` **is** the cross-browser way of preventing the  
> default action.
>
> - `return false` prevents the default action and stops the event  
> propagation.
>
>
>
> > On Oct 16, 11:16 pm, Hullah <[EMAIL PROTECTED]> wrote:
> >> I have a page with input textboxes and input buttons on it.  All are
> >> contained in a form.  I don't want the Enter button to submit the
> >> form, so I call preventDefault() on all texboxes.  I also don't want
> >> the input button to submit the form, so I call preventDefault() on  
> >> the
> >> input button.
>
> >> But, if I call the button.click() event for when Enter is pressed  
> >> in a
> >> textbox (to simulate a click on the button) it submits the form.  It
> >> seems as if something is not working like it should.
>
> >> Now...if I "return false" instead of preventDefault(), it works as I
> >> would expect.  But I would have thought that the purpose of
> >> preventDefault() is to cancel the default action of the event, as in
> >> this case to cancel form submission.
>
> >> Any help with this is greatly appreciated!  Following is some sample
> >> code that exhibts the behavoir.
>
> >> Thanks,
> >> Hullah
>
> >>  >>   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> >> http://www.w3.org/1999/xhtml";>
> >>     
> >>         Test
> >>          >> src="jquery-1.2.6.js">
> >>         
> >>           $(function() {
> >>             $(":text").keypress(function(e) {
> >>               if (e.which == 13) {
> >>                 e.preventDefault();
> >>               }
> >>             });
> >>             $("#txt").keypress(function(e) {
> >>               if (e.which == 13) {
> >>                 $("#btn").click();
> >>               }
> >>             });
> >>             $("#btn").click(function(e) {
> >>               e.preventDefault();
> >>               alert("Button clicked");
> >>             });
> >>           });
> >>         
> >>     
> >>     
> >>       
> >>         
> >>           
> >>           
> >>         
> >>       
> >>     
> >> 
>
>


[jQuery] Re: event.preventDefault() seems to fail

2008-10-17 Thread Choan Gálvez


On Oct 17, 2008, at 7:37 PM, ricardobeat wrote:



It should work... but in jQuery 'return false' is the standard cross-
browser way of preventing the default action anyway,


Not exactly.

- `preventDefault()` **is** the cross-browser way of preventing the  
default action.


- `return false` prevents the default action and stops the event  
propagation.





On Oct 16, 11:16 pm, Hullah <[EMAIL PROTECTED]> wrote:

I have a page with input textboxes and input buttons on it.  All are
contained in a form.  I don't want the Enter button to submit the
form, so I call preventDefault() on all texboxes.  I also don't want
the input button to submit the form, so I call preventDefault() on  
the

input button.

But, if I call the button.click() event for when Enter is pressed  
in a

textbox (to simulate a click on the button) it submits the form.  It
seems as if something is not working like it should.

Now...if I "return false" instead of preventDefault(), it works as I
would expect.  But I would have thought that the purpose of
preventDefault() is to cancel the default action of the event, as in
this case to cancel form submission.

Any help with this is greatly appreciated!  Following is some sample
code that exhibts the behavoir.

Thanks,
Hullah

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>

Test


  $(function() {
$(":text").keypress(function(e) {
  if (e.which == 13) {
e.preventDefault();
  }
});
$("#txt").keypress(function(e) {
  if (e.which == 13) {
$("#btn").click();
  }
});
$("#btn").click(function(e) {
  e.preventDefault();
  alert("Button clicked");
});
  });



  

  
  

  






[jQuery] Re: event.preventDefault() seems to fail

2008-10-17 Thread ricardobeat

It should work... but in jQuery 'return false' is the standard cross-
browser way of preventing the default action anyway, so I'd recommend
sticking to that.

- ricardo

On Oct 16, 11:16 pm, Hullah <[EMAIL PROTECTED]> wrote:
> I have a page with input textboxes and input buttons on it.  All are
> contained in a form.  I don't want the Enter button to submit the
> form, so I call preventDefault() on all texboxes.  I also don't want
> the input button to submit the form, so I call preventDefault() on the
> input button.
>
> But, if I call the button.click() event for when Enter is pressed in a
> textbox (to simulate a click on the button) it submits the form.  It
> seems as if something is not working like it should.
>
> Now...if I "return false" instead of preventDefault(), it works as I
> would expect.  But I would have thought that the purpose of
> preventDefault() is to cancel the default action of the event, as in
> this case to cancel form submission.
>
> Any help with this is greatly appreciated!  Following is some sample
> code that exhibts the behavoir.
>
> Thanks,
> Hullah
>
>    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
>     
>         Test
>          src="jquery-1.2.6.js">
>         
>           $(function() {
>             $(":text").keypress(function(e) {
>               if (e.which == 13) {
>                 e.preventDefault();
>               }
>             });
>             $("#txt").keypress(function(e) {
>               if (e.which == 13) {
>                 $("#btn").click();
>               }
>             });
>             $("#btn").click(function(e) {
>               e.preventDefault();
>               alert("Button clicked");
>             });
>           });
>         
>     
>     
>       
>         
>           
>           
>         
>       
>     
>