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 13 of 13

Thread: validate/submit

  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,649
    Thanks
    1
    Thanked 0 Times in 0 Posts

    validate/submit

    I'm using a link to submit...but it's not validating with validate()

    <form name="mail" onSubmit="return validate(this);" method="post" action="blah.php">
    Form Here
    <a href="#" onClick="this.mail.submit();">SEND</a>
    </form>

    I've also tried <a href="#" type="submit">SEND</a> and it seems to submit but doesn't validate.

    It works fine just using a submit button <input type="submit" value="SEND">...but I need to submit via the <a href>.

    Thanks
    Last edited by zoobie; 07-13-2003 at 06:31 AM.
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the submit() method for forms does not trigger the onsubmit event.

    So, you'll need to peform this via onclick of the link.

    P.S.
    Why are you relying on JS to be your submit button? This is generally a Bad Idea&trade;
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,649
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yes...The onclick="this.mail.submit()" over-rides the onSubmit...but since I'm using an image swap on hover via the <a href> for the button, I'll have to use this...unless you or anyone else has a better way.

    I've tried <a href="#" onClick="if (validate(this)) {this.mail.submit();}" class="button">SEND</a> ...but it needs the "return" in there somewhere.

    Thanks
    Last edited by zoobie; 07-13-2003 at 07:50 AM.
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can return false to a click event on a link to cancel that click.

    Why not use an input type=image? They behave just like submit buttons!
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,649
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I know...but I'd have to add a bunch of mouseover/out code...and have it load 2 more images...inefficient when I have the a href's hover already set up.

    Ugh...Surely, there's a good way to do this...and don't call me Shirley.
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I stand by my opinion. It is better to let the HTML handle the critical operation (form submission) and JS handle the non-critical operation (rollover).

    It could be done with what you have, and I'll show you only after you seriously consider why you are really doing this, and who it will effect.
    Last edited by beetle; 07-13-2003 at 08:37 AM.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,649
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Eh?

    Forget it...I just wrote a little function...Sweet

    Consider what? A 7% population of coke-bottled, pocket-protected geeks who have turned off their javascript? Not much to consider really...
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #8
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi zoobie,

    I experience the same problem, and don't want to go the beetle-way this time.

    Mine is even more advanced, I think, because the onClick event is located outside the form tags.

    Do You have any idea how to solve this?

    Thanks in advance,
    Jerome

  • #9
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Call your validate function with the onclick. If it is valid, submit the form from that funciton, otherwise show an error message.

  • #10
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmmm...

    The problem is that I want to validate (this), however my onClick event is located outside the form tags

    jerome

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the basics:

    function validateForm()
    {
    if (everythingIsOk)
    return true
    else
    return false;
    }


    <a href="#" onclick="(validateForm())? document.forms[0].submit() : alert('You didn't fill out the form properly!');">Submit Form</a>


    -------------------

    Of course you could just have the validation function go ahead and submit the form if everything's ok which would simplify the link to:

    <a href="#" onclick="validateForm();">Submit Form</a>
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #12
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Originally posted by Jerome
    Hmmm...

    The problem is that I want to validate (this), however my onClick event is located outside the form tags

    jerome
    If you aren't within form tags, "this" will not reference that form. Reference the form like document.myform.submit().

  • #13
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,649
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yep...You have to name your form then submit like arnyinc said from anywhere:
    <form name="fred" action="mail.php" method="post">
    Form here
    </form>
    More html
    Still more html
    <a href="#" onclick="this.fred.submit();">SEND</a>


    I'm sure beetle is right...but in some cases, you want to actually use javascript to validate then submit like so:

    function validate(form) {
    // validate form
    if (formIsValid) {
    form.submit();
    return true;
    }
    else {
    return false;
    }
    }

    and in your link:

    <a href="#" onClick="return validate(document.forms[0]);}">SEND</a>
    Last edited by zoobie; 07-16-2003 at 03:55 AM.
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">


  •  

    Posting Permissions

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