Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts

    alert confirmation with Anchor Link

    Code:
    <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.

    Code:
    <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
    Last edited by joonstar; 08-27-2004 at 12:54 AM.
    Get my greedy up

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    <a href="http://javaranch.com" onclick="return verify()">asdf</a>
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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.

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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,
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Calling document.formRef.onsubmit() will surely execute the onsubmit handler but will not submit the page.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •