Originally posted by Bear Bibeault:
You don't want to capture the key, you want to prevent the form from submitting. Add a submit handler for the form that returns false.
Originally posted by Bear Bibeault:
Right, what we've done is to block form submission. In the event handler you can check the target to see if the button initiated the submission and let it go through (by not returning false).
Originally posted by Bear Bibeault:
In the event instance passed to the submit handler, the target property will be a reference to the element that initiated the event.
The return of false from the submit handler is what blocks the form submission. But...Originally posted by Michael Hubele:
I am confused. Like if I use the return false that basically blocks the enter button from being used. How is adding a event handler going to help me?
So you never want to submit the form?I am not submitting anything to the server... I am just trying to get it so when the user gets to my flashcard page they see a text box, a image box and a button.
Ah, that's not what I thought you were tryng to do initially.I just want to make it so they don't have to type there answer then move their mouse to the button and click on it. I want them to be able to use the enter key to click on the button and then that buttons click event gets launched.
Originally posted by Bear Bibeault:
Ah, that's not what I thought you were tryng to do initially.
OK, the submit handler that I posted will prevent the form from ever getting submitted (unless you call its submit() method), but that won't do anything to trigger your button click function.
For that, you'll need to add a keypress handler to the text field to check for the Enter key. When you detect it, you can trigger the button's click handler. If you've established the click handler with jQuery, you can trigger it by calling the click() method (with no params) after wrapping the button.
[ June 21, 2008: Message edited by: Bear Bibeault ]
Originally posted by Michael Hubele:
[QB]
My button is just a regular input button with type="button".
I am not sure where to put that code in the textbox. I got to events for it setup the blur event and click event.
Both don't seem to be the right place to put it. Like if I put it in the click even that mean the second I click on it that event will look at it and since the enter key has not been pressed it will never run.
Same with on blur that is only if they leave the event that gets fired.
So am I suppose to add another event?
and do you call it like this?
$("#startQuiz").click();
edit-
Ah I missed where you said keypress handler.
I been looking around and I see that it seems you need to test for firefox and ie keyevents? Is this correct?
I don't even know how this works. not sure how you can do a || statement in a variable like that. Or why you need to check for .which and a keycode.
Also I don't understand this. Is there something special in text boxes that cause post back automatically. If I don't have that original blocker in there and I hit the enter key. It will go and click the button and then refresh the page.
Good. So the button click will not trigger a form submission. The Enter key in a field will do so in some circumstances; hence the submit handler that blocks it.Originally posted by Michael Hubele:
My button is just a regular input button with type="button".
Not if you are using jQuery. It will normalize the event instance so you don't have to worry about IE's nonsense.I been looking around and I see that it seems you need to test for firefox and ie keyevents? Is this correct?
Originally posted by Bear Bibeault:
Not if you are using jQuery. It will normalize the event instance so you don't have to worry about IE's nonsense.
[ June 21, 2008: Message edited by: Bear Bibeault ]
Originally posted by Bear Bibeault:
If you don't want the form to be submitted as a fill-page reload, why did you change your button to a submit button?
Originally posted by Bear Bibeault:
The easiest way to re-route a form through Ajax is to grab the jQuery Form plugin and use its ajaxSubmit() method.
Originally posted by Bear Bibeault:
Do the submit or do the click handling yourself. Not both.
Originally posted by Bear Bibeault:
Make Default.aspx the action of the form, and embed a hidden input to contain the request parameter.
The whole point of ajaxSubmit() is that you set up the <form> just as if you were going to submit the form normally, and it re-routes it as an Ajax request.
You might also want to check out ajaxForm() which sets up the form as such without you having to even declare the submit handler.
[ June 23, 2008: Message edited by: Bear Bibeault ]
Originally posted by Bear Bibeault:
or, just put this in the ready-handler:
and it will handle everything.
[ June 23, 2008: Message edited by: Bear Bibeault ]
Originally posted by Bear Bibeault:
The beauty of ajaxSubmit() and ajaxForm() is that they will automatically marshal and encode the request params for you. You don't have to do anything on your own. The submission will act just like a "normal" form submission, except that it will be made via Ajax rather than a full-page reload.
So, yeah, easier that $.post() because it does the form field gathering for you.
Originally posted by Michael Hubele:
So if I put my checkboxes in a form and then post it it will gather all that for me?
Nope, sorry. (No interest in such technologies.)You don't know asp.net and C# by any chance?
Individually. HTTP has no concept of an array.Originally posted by Michael Hubele:
how would the checkboxes be packaged? would they all come invidually or as an array?
An array of what? Most often, multiple elements will be passed to the server by creating multiple form elements with the same name. Most server-side web containers make these easy to gather as an array. (No, I don't know how in ASP/C# -- in Java, it's a single method call).On a side note how would you pass an array to the server?
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|