Strange Safari onClick problem

J

Jacqui

Hi,

I am trying to write a webpage that has a form on it, which gets
submitted when a button is pressed, but also has an onclick event
which does some DOM manipulation to display a waiting page.

The issue that I am facing is that in Safari, a blank screen is being
displayed rather than the waiting page. This is only happening if
there are form tags around the button

i.e., this works and brings up the waiting page:

<input type="submit" name="submit" onclick='return interstitial();'/>

whereas this does not:

<form method="get" action="<slow loading page>">
<input type="submit" name="submit" onclick='return
interstitial();'/>
</form>

This does not appear to be a problem in Firefox/IE. Has anybody else
faced this problem and would be willing to help me out with this?

Many thanks in advance,
Jacqui
 
V

VK

Hi,

I am trying to write a webpage that has a form on it, which gets
submitted when a button is pressed, but also has an onclick event
which does some DOM manipulation to display a waiting page.

The issue that I am facing is that in Safari, a blank screen is being
displayed rather than the waiting page. This is only happening if
there are form tags around the button

i.e., this works and brings up the waiting page:

<input type="submit" name="submit" onclick='return interstitial();'/>

whereas this does not:

<form method="get" action="<slow loading page>">
<input type="submit" name="submit" onclick='return
interstitial();'/>
</form>

This does not appear to be a problem in Firefox/IE. Has anybody else
faced this problem and would be willing to help me out with this?

<form method="GET"
action="slow_loading_page.cgi"
target="hidden_frame"
onsubmit="return interstitial(this)">
<!-- other form elements -->
<input type="submit">
</form>
<iframe name="hidden_frame" src="blank.html"
style="display: none !important"></iframe>

where

where interstetial does validation, sets waiting message and returns
true

Because form submission means leaving the current page, you have to
dump the server output to a hidden frame, otherwise it has no sense to
display any DOM waiting message - they will disappear a ms later.

If you are using an ajaxoid to submit your form then respectively you
have to cancel form submission and do the job manually, in such case
iframe is not needed:

<form method="GET"
action="slow_loading_page.cgi">
<!-- other form elements -->
<input type="button" value="Submit"
onclick="interstitial(this.form)">
</form>

1) interstitial has to show waiting message first, then over
setTimeout proceed with form submission: otherwise the screen will
never be updated.
2) a fallback should be provided in case Javascript disabled. One of
options:

<script>
document.write(''.concat(
'<input type="button" value="Submit"',
' onclick="interstitial(this.form)">'));
</script>
<noscript>
<input type="submit">
</noscript>
 
B

Bart Van der Donck

Jacqui said:
The issue that I am facing is that in Safari, a blank screen is being
displayed rather than the waiting page.  This is only happening if
there are form tags around the button

i.e., this works and brings up the waiting page:

<input type="submit" name="submit" onclick='return interstitial();'/>

whereas this does not:

<form method="get" action="<slow loading page>">
    <input type="submit" name="submit" onclick='return
interstitial();'/>
</form>

Two errors in your logic:

1. A user does not need to click the submit-button in order to submit
the form; he might hit the Enter-key as well.

2. http://www.w3.org/TR/html401/interact/scripts.html#adef-onclick

| The onclick event occurs when the pointing device
| button is clicked over an element. This attribute may
| be used with most elements.

(especially note the vague "most elements")

And a few sentences higher:

| Authors of HTML documents are advised that changes are
| likely to occur in the realm of intrinsic events (e.g.,
| how scripts are bound to events).

Seems reason enough for me not to trust onclick-events for submit-
buttons accross browsers.

The recommended way:

<form method="get" action="script.php"
onsubmit="return interstitial();">
<input type="submit">
</form>
 
J

Jacqui

Two errors in your logic:

1. A user does not need to click the submit-button in order to submit
the form; he might hit the Enter-key as well.

2.http://www.w3.org/TR/html401/interact/scripts.html#adef-onclick

    | The onclick event occurs when the pointing device
    | button is clicked over an element. This attribute may
    | be used with most elements.

(especially note the vague "most elements")

And a few sentences higher:

    | Authors of HTML documents are advised that changes are
    | likely to occur in the realm of intrinsic events (e.g.,
    | how scripts are bound to events).

Seems reason enough for me not to trust onclick-events for submit-
buttons accross browsers.

The recommended way:

   <form method="get" action="script.php"
    onsubmit="return interstitial();">
   <input type="submit">
   </form>

Hi,

Thank you for your help. We have managed to get round this in the
following manner:

In the mark up created an interstitial panel which is included based
on browser type. So when the browser is safari, it is then placed on
the page in a hidden state. When the form is submitted a further
check is carried out on browser type, if the browser is safari this is
simply shown and the rest of the screen hidden using style: display
block/none respectively. All other browser will create this page by
doming.

As it’s a loading issue: this gets around it by loading the content
prior to a submit, just hidden on page until a submit is carried out.

This is a bit hacky…but it works.

Cheers,
Jacqui
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top