Connecting Tech Pros Worldwide Help | Site Map

forms using keyPress onChange to submit or not to submit

awebguynow
Guest
 
Posts: n/a
#1: Dec 30 '05
to submit or not to submit - that is the question
and I'm going to be designing some lengthy forms, where many of the
fields may be populated with data, and the user may only want to view
it.

In a perfect world, I'd have 2 buttons: Close and Submit - disabled
and Submit would become enabled - immediately - if data was changed.
otherwise the user could click "Close" and a php script could redirect
(header) to Default pg.

Any articles on this ? Has any one attempted this ? have advice ?

Danny
Guest
 
Posts: n/a
#2: Dec 30 '05

re: forms using keyPress onChange to submit or not to submit




<input ....
onkeypress="this.form.MYSUBMIT.disabled=false;this .onkeypress=null;">

<input type="submit" disabled name="MYSUBMIT">

afterwards enabling MYSUBMIT, it removes itself, to avoid any
further keypress checks once the typing started, no point checking
each time.


Danny
awebguynow
Guest
 
Posts: n/a
#3: Dec 30 '05

re: forms using keyPress onChange to submit or not to submit


Thank you for your response.
My only concern is that this may be cumbersome to code with 30+ input
fields.
Is there a good way to apply this to the whole form ?

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#4: Dec 30 '05

re: forms using keyPress onChange to submit or not to submit


awebguynow wrote:
[color=blue]
> Thank you for your response.[/color]

Which response?

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
<URL:http://www.safalra.com/special/googlegroupsreply/>
[color=blue]
> My only concern is that this may be cumbersome to code with 30+ input
> fields.
> Is there a good way to apply this to the whole form ?[/color]

The `keypress' event is documented (in MSDN) and tested (in Mozilla/5.0
rv:1.8) to bubble:

<form ...
onkeypress="this.elements['MYSUBMIT'].disabled = false;
this.onkeypress = null;">
...
</form>

<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onkeypress.asp>


PointedEars
Jasen Betts
Guest
 
Posts: n/a
#5: Dec 30 '05

re: forms using keyPress onChange to submit or not to submit


On 2005-12-30, awebguynow <i_dvlp@hotmail.com> wrote:
[color=blue]
> to submit or not to submit - that is the question
> and I'm going to be designing some lengthy forms, where many of the
> fields may be populated with data, and the user may only want to view
> it.
>
> In a perfect world, I'd have 2 buttons: Close and Submit - disabled
> and Submit would become enabled - immediately - if data was changed.
> otherwise the user could click "Close" and a php script could redirect
> (header) to Default pg.
>
> Any articles on this ? Has any one attempted this ? have advice ?[/color]

it doesn't sound like it will give much trouble.

start with submit enabled and disable it using javascript (so that users
with script turned off can still submit)

give the editable fields an onchange event handler that enables the submit
button

but anyway: what harm is there in always submitting?

Bye.
Jasen
Jasen Betts
Guest
 
Posts: n/a
#6: Dec 30 '05

re: forms using keyPress onChange to submit or not to submit


On 2005-12-30, awebguynow <i_dvlp@hotmail.com> wrote:[color=blue]
> Thank you for your response.
> My only concern is that this may be cumbersome to code with 30+ input
> fields.
> Is there a good way to apply this to the whole form ?[/color]

you could apply onkeypress to the <form>,

onkeypress won't help if the user edits the form without using the keyboard.
- you need onchange on the fields too.

you could do a script that loops through the form fields and installs the
handler.

Bye.
Jasen
Closed Thread


Similar JavaScript / Ajax / DHTML bytes