input submits regardless of event return; explain this fix please

O

okey

<input type="submit"
class="button-bold"
name="change_resolution"
id="change_resolution"
value="count $single"
onClick="return changeResolution
($res_id,'$single');"
/>

Firing onClick submitted no matter what changeResolution() returned.
The fix for onClick was:

<input type="submit"
class="button-bold"
name="change_resolution"
id="change_resolution"
value="count $single"
onClick="this.disabled = true; var sbmt =
changeResolution($res_id,'$single'); this.disabled = false; return
sbmt;"
/>

Would someone please explain it. I can see submit is being disabled,
but why? Thank you.
 
O

okey

If you don't want a form to be submitted, put the listener on the
'submit' event of the *form(, not a button.  If anyone pressed 'enter'
to submit a form in your example above, nothing would be fired at all.

But it works just fine.
 
T

Thomas 'PointedEars' Lahn

okey said:
<input type="submit"
class="button-bold"
name="change_resolution"
id="change_resolution"
value="count $single"
onClick="return changeResolution
($res_id,'$single');"
/>

Firing onClick submitted no matter what changeResolution() returned.
The fix for onClick was:

<input type="submit"
class="button-bold"
name="change_resolution"
id="change_resolution"
value="count $single"
onClick="this.disabled = true; var sbmt =
changeResolution($res_id,'$single'); this.disabled = false; return
sbmt;"
/>

Would someone please explain it. I can see submit is being disabled,
but why? Thank you.

I'll reword your question for you: "What have I done wrong?"

1. Your markup is not Valid.
2. You have used XHTML when you should have used HTML.
3. You have tried to cancel the `click' event on the submit button
when you should have tried to cancel the `submit' event of the form.
4. You are preventing users from submitting the form again
using the submit button in case the document is cached.
(4a. Assumption: You are trying to change the window size
which is forbidden per user preferences, so changeResolution()
throws an exception that is not handled by your code.)
5. You have a *client-side* problem, but you have not posted
the *client-side* code.
6. Assumption: You have not read the FAQ before posting.
Do it now, especially <http://jibbering.com/faq/#posting>
7. You have not followed the FAQ recommendations.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top