I see, i guess i have to pay more attention :)
OK, how about this.
var submitType = false;
$("your single form id").submit(function() {
if(submitType == "type1") {
// do something
} else if(submitType == "type2") {
// do something
} else {
return false;
}
});
$("#ctl00_contentPlc_txtPassword").keydown(function(e){
// set type
submitType = "type1";
// fire submit.
$("your single form id").submit();
});
$("#ctl00_contentPlc_txtOtherPassword").keydown(function(e){
// set type
submitType = "type2";
// fire submit.
$("your single form id").submit();
});
/christian
Dan Atkinson wrote:
> Christian,
>
> Thanks for the reply but, as I mentioned there is only one form on the page,
> and two submit buttons inside it.
>
> Your code sample assumes that there is more than one form and wouldn't work
> on a single form.
>
>
>
> Christian Bach wrote:
>> Hi,
>>
>> let's say we have the following html i the page.
>>
>> <form id="form1">
>> <input type="text" name="username" class="formItem"/>
>> </form>
>>
>> <form id="form2">
>> <input type="text" name="username_again" class="formItem"/>
>> </form>
>>
>> <script>
>> var currentForm = false;
>> var triggerKeyCode = 13;
>> $(document).ready(function() {
>> $(".formItem").focus(function() {
>> currentForm = $(this).parent();
>> });
>> $(this).keyDown(function(e) {
>> if (!e) var e = window.event
>> if (e.keyCode) code = e.keyCode;
>> else if (e.which) code = e.which;
>>
>>
>> if(currentForm && code == triggerKeyCode) {
>> currentForm.submit();
>> }
>>
>> });
>> });
>>
>> this is just of the top of my head, and is not tested!
>>
>> Best regards
>> Christian
>>
>>
>> Dan Atkinson wrote:
>>> Hey all!
>>>
>>> Ok, right to the point here!
>>>
>>> I have a page in ASP.NET which has two sets of username and password
>>> boxes
>>> and two sets of submit buttons. Because it is ASP.NET, there can only be
>>> one
>>> form in a page.
>>>
>>> The problem in a normal page is that, when the user presses enter on the
>>> keyboard, the first submit control is triggered. What if someone enters
>>> info
>>> in the second username and password boxes? Well, the page simply doesn't
>>> know which control the user was in when they hit enter.
>>>
>>> So... I wrote something which determines which textbox the user was in
>>> when
>>> they pressed enter (keycode 13)
>>>
>>> $(document).ready(function(){
>>> $("#ctl00_contentPlc_txtPassword").keydown(function(){
>>> //The user pressed a key in the password textarea
>>> if ((event.which && event.which == 13) || (event.keyCode &&
>>> event.keyCode == 13))
>>> {
>>> //The user pressed enter. Check if the relevant textboxes are
>>> filled
>>> correctly. If not, show the error and return false
>>> if (!CheckLogin())
>>> return false;
>>> else
>>> //User has filled in the textboxes properly. Now simulate a click
>>> on
>>> the first button.
>>> $("#ctl00_contentPlc_btnCheck").click();
>>> }
>>> });
>>>
>>> $("#ctl00_contentPlc_txtOtherPassword").keydown(function(){
>>> //The user pressed a key in the password textarea
>>> if ((event.which && event.which == 13) || (event.keyCode &&
>>> event.keyCode == 13))
>>> {
>>> //The user pressed enter. Check if the relevant textboxes are
>>> filled
>>> correctly. If not, show the error and return false
>>> if (!CheckOtherLogin())
>>> return false;
>>> else
>>> //User has filled in the textboxes properly. Now simulate a click
>>> on
>>> the first button.
>>> $("#ctl00_contentPlc_btnOtherCheck").click();
>>> }
>>> });
>>> });
>>>
>>> There is a problem however. The script works, but doesn't actually
>>> simulate
>>> a click on the second button. If I replace
>>> $("#ctl00_contentPlc_btnOtherCheck").click(); with alert("hello");, I'll
>>> get
>>> a lovely message come up when I press enter in the second password
>>> textarea.
>>> So this indicates to me that the script is working ok, but the button
>>> isn't
>>> being fired. The button exists and I can reference it, but I simply can't
>>> fire it.
>>>
>>> I've also tried $("[EMAIL PROTECTED]").get(1).click(); but this doesn't
>>> work either (note, that the button is an image button).
>>>
>>> Is there anyone who has had a similar problem and solved it?
>>>
>>> Cheers,
>>>
>>> Dan
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>>
>>
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/