...

View Full Version : alert confirmation with Anchor Link



joonstar
08-27-2004, 01:49 AM
<SCRIPT LANGUAGE=JAVASCRIPT>
function verify(){
msg = "Are you absolutely sure that you want to submit this form?";
//all we have to do is return the return value of the confirm() method
return confirm(msg);
}
</SCRIPT>

</HEAD>

<BODY>
<FORM ACTION="action.cfm" onSubmit="return verify()">
Name: <INPUT TYPE=TEXT NAME="myName" size=30><BR>
<INPUT TYPE=SUBMIT VALUE="Submit">
</FORM>
</BODY>


The above code gives an alert confirmation when a user clicks the submit button using input form tag.


Can I give the alert confirmation when a user clicks the submit button using Anchor Link?

The following code doesn't work correctly, but it will help you to understand what I am trying to do.



<SCRIPT LANGUAGE=JAVASCRIPT>
function verify(){
msg = "Are you absolutely sure that you want to submit this form?";
//all we have to do is return the return value of the confirm() method
return confirm(msg);
}
</SCRIPT>

</HEAD>

<BODY>
<a href="action.cfm" onSubmit="return verify()"> Submit </a>
</BODY>


Thanks in Advance

A1ien51
08-27-2004, 03:02 AM
<a href="http://javaranch.com" onclick="return verify()">asdf</a>

glenngv
08-27-2004, 04:51 AM
Only <form> tag has onsubmit event handler.

<form action="action.cfm" name="myform">
<a href="#" onclick="if (verify()) document.myform.submit();return false">Submit</a>

I can't use form onsubmit handler because document.formRef.submit() suprisingly doesn't trigger it.

liorean
08-27-2004, 05:03 AM
Why don't you rig that up to use a call to onsubmit instead of submit? IIRC (I might be wrong here, I haven't been working with DOM0 events lately) all event handlers trigger the corresponding event unless they return false, so calling onevent actually triggers the call to event,

glenngv
08-27-2004, 07:22 AM
Calling document.formRef.onsubmit() will surely execute the onsubmit handler but will not submit the page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum