Click to See Complete Forum and Search --> : designate which img field when enter key struck?


claustrophonic
05-24-2003, 08:13 AM
Is it possible to use js to designate which img field will submit the form when the user hits the 'enter' key? my form works fine if they click any submit button, but has problems if they hit enter after typing in a field.

something like <input type="text" name="city" onEnterKey="form.imageField1.submit">

sorry my javascript is not too good.

khalidali63
05-24-2003, 08:34 AM
on document level capture events for keypress and key up,
the key pressed value for enter key is "13"

put a simple condition

if(event.keyCode==13){
your submit routine here
}

claustrophonic
05-24-2003, 09:46 AM
can I associate that event with certain text inputs of the form?

or would i need to check if "these 4 form fields over here" are blank, OR "those 4 form fields over there" are blank? (when I'm coding the submit routine)

know what I"m sayin?

khalidali63
05-24-2003, 09:55 AM
Originally posted by claustrophonic
know what I"m sayin?

I am afraid not.
Please elaborate.

claustrophonic
05-24-2003, 10:41 AM
ok, there are 8 text fields (grouped in two sets of four) in my form, two checkboxes and one select drop-down. There are also three img fields that submit the form. Clicking on any of them works fine.

However, if the user hits enter while in the second set of text fields, the img field associated with the first set of text fields behaves as if it was clicked. This doesn't work for me. I need for the second img field to send its value when the user is entering text in the second set of text fields.

[the reason for this is that my server-side form validation in the form action page checks for the presence of which img was used to submit]

Thanks so much for your generous feedback so far!

khalidali63
05-24-2003, 10:53 AM
Now this makes way more sense..:p

here is the quickest solution that comes to mind,there can be other better solutions for this too.

in th eonkyup event of the text fieldcall a function say

function setBlock(val){
//global variable
whichBLock = val;

}

in the keyup event
first block of text fields
onkyeup="setBlock('first');"

second block of textfields
onkyeup="setBlock('second');"

then when you trap the keycode==13
you can explicitly create onclick event call from appropriate submit button

claustrophonic
05-26-2003, 11:14 AM
explicitly create onclick event call from appropriate submit button
I'm afraid I'm not good enough at javascript to implement. Can you be more explicit?

claustrophonic
05-26-2003, 12:18 PM
never mind i changed the way my server-side scripting does the form validation, so now it doesn't matter how the user submits the form, it will be handled accordingly. Thx for you feedback!

khalidali63
05-26-2003, 12:19 PM
great...:p