aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Handle multiple click of an image hyperlink Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Handle multiple click of an image hyperlink" Watch "Handle multiple click of an image hyperlink" New topic
Author

Handle multiple click of an image hyperlink

Kishan Kumar
Ranch Hand

Joined: Sep 26, 2000
Posts: 130
Hi,
Iam using an image hyperlink to submit a form
a href submitForm img src submit.jpg a
In submitForm javascript function iam handling in such a way that the first click submits the form and subsequent clicking returns an alert that form is already submitted.
script language JavaScript

script
This does not work...when I click first the form appears to be submitting..but on clicking again the alert appears but the ealrier submit does not process. The form processing stops and any further click on image just produces the alert.
This seems to work when I change the image line as
a href onClick submitForm() img src submit.jpg a

Is there an alternative to get it working without using the onclick function. heard onclick does not work in older versions of netscape.
Note : I had a hard time trying to add HTML code to message but was always getting an error. so just did not put the tags here.
Please help


Regards,<BR>V. Kishan Kumar
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
i changed the code little bit
check this
var isSubmitComplete = false;

function submitForm(){
if(!isSubmitComplete){
isSubmitComplete = true;
alert("Form submit");
}else{
alert("Form already submitted");
}
}
Kishan Kumar
Ranch Hand

Joined: Sep 26, 2000
Posts: 130
Hi,
There is no problem with the logic. The javascript function executes the way it should in both my code and yours. The problems is the form appears to have submitted....but when I click the image the second time the alert appears, but the earlier submission of form does not get processed.
It gets processed only if i use the onClick function instead of the href function.
I would like the change to minimise since i have over a 100 href things that have to be changed if onClick is the only solution.
Thanks for your time
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The alert is probably causing the form to stop submitting. I would persoanlly just not have the alert. I would do something like this:

with your form

The on submit handler will allow or not allow the form to be submitted. All you need to do is have the form submitted anyway you want from a button to a text link to an image.
Hope this helps
Eric
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
onClick function do have problem even in netscape 6
why not disable the link after submitting the form by dhtml???
just a thought
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
I tested the code ...it is giving the alert message not processing the form.
i think ( i may be wrong) the solution according to your req using server side validation to check wheather the form has submitted twice and in the link
a href="javascript:void(document.myform.submit())"
Originally posted by Kishan Kumar:
Hi,
Iam using an image hyperlink to submit a form
a href submitForm img src submit.jpg a
In submitForm javascript function iam handling in such a way that the first click submits the form and subsequent clicking returns an alert that form is already submitted.
script language JavaScript

script
This does not work...when I click first the form appears to be submitting..but on clicking again the alert appears but the ealrier submit does not process. The form processing stops and any further click on image just produces the alert.
This seems to work when I change the image line as
a href onClick submitForm() img src submit.jpg a

Is there an alternative to get it working without using the onclick function. heard onclick does not work in older versions of netscape.
Note : I had a hard time trying to add HTML code to message but was always getting an error. so just did not put the tags here.
Please help

Kishan Kumar
Ranch Hand

Joined: Sep 26, 2000
Posts: 130
Hi sunitha,
I did not get what you meant in your last reply...Eric's solutions seems to be working...but Netscape 4.x gives "Transer Interrupted Error" when clicked twice or more on the same image with eric's proposed solution.
onlick does not work with Netscape 6 and onsubmit is not working properly with netscape 4 :-))
Was just thinking what to do
Thanks
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
I thought u dont want to call the fn on submit even of the form.
onSubmit should work on the versions of the browser
do check with this also
var submitcount=0;

function checkSubmit()
{

if (submitcount == 0)

{ submitcount++; return true; }
else
{ alert('This form has already been submitted.' ); return false; }

}
*****
and
form onSubmit="return checkSubmit();"
Kishan Kumar
Ranch Hand

Joined: Sep 26, 2000
Posts: 130
Thanks all. onsubmit solution works fine.
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handle multiple click of an image hyperlink