Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Strange Safari onClick problem

Reply
Thread Tools

Strange Safari onClick problem

 
 
Jacqui
Guest
Posts: n/a
 
      04-21-2008
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
 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      04-21-2008
On Apr 21, 12:57 pm, Jacqui <(E-Mail Removed)> wrote:
> 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>


 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      04-21-2008
Jacqui wrote:

> 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/interac...l#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>

--
Bart
 
Reply With Quote
 
Jacqui
Guest
Posts: n/a
 
      04-23-2008
On 21 Apr, 15:49, Bart Van der Donck <(E-Mail Removed)> wrote:
> Jacqui wrote:
> > 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/interac...l#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>
>
> --
> *Bart


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
onclick on option not working on IE or safari James Black Javascript 3 04-12-2006 03:12 AM
Overriding an onclick with another onclick tomlong@gmail.com Javascript 4 01-26-2006 09:26 PM
button.onclick = new Function("func2()") + button.onclick foldface@yahoo.co.uk Javascript 2 09-26-2005 08:13 AM
onclick image coordinates from Konqueror and Safari Roger Javascript 1 09-26-2005 02:31 AM
document.onclick=doIt() same as document.onclick=doIt ? bob Javascript 3 08-21-2003 12:14 PM



Advertisments