SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2004
    Posts
    419
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stuck on form with multiple buttons - can't figure out how to achieve something

    Hi,

    I have this form - test page here:
    http://jimpix.co.uk/ecards/test.asp?...essage&c=1#swf

    I have a button at the top of the page:

    Code HTML4Strict:
    <button type="button" value="Refresh ecard above with your own content &raquo;" id="button0" name="button0" onclick="return onbutton0();">Refresh ecard above with your own content &raquo;</button>

    Linked to this javascript:

    Code JavaScript:
    function onbutton0()
    {
        document.theForm.action = "normal-ecard.asp?id=<%=e%>&tag=<%=tag%>&c=<%=c%>#swf"
        document.theForm.submit();             // submit the page
        return true;
    }

    Then there's a "Preview" button at the bottom - a regular "submit" button, which calls a javascript function to validate the form input, called via this in the form HTML:

    Code HTML4Strict:
    <form method="post" action="preview.asp" name="theForm" id="theForm" style="padding:0px; border:0px;" onsubmit="return valForm(this)">

    Usually people have to preview the ecard before sending it, but I'd like to add an option to allow people to send right away, without the preview bit.

    However, I can't see how to do it, because the action on the form is to send the user to "preview.asp".

    The page to send directly is called "process.asp".

    However, I can't just add this:

    Code JavaScript:
    function onbuttontest()
    {
        document.theForm.action = "process.asp"
        document.theForm.submit();             // submit the page
        return true;
    }

    And this:

    Code HTML4Strict:
    <button type="button" value="Send Immediately" id="onbuttontest" name="onbuttontest" onclick="return onbuttontest();">Send Immediately</button>

    Because then the form validation function (valForm) will not be called.

    I tried this:

    Code HTML4Strict:
    <button type="button" value="Send Immediately" onclick="return valForm(this)">Send Immediately</button>

    But that doesn't work...

    I wonder if there is a way I can do it - any advice much appreciated.

    Thanks!

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <button type="button" value="Send Immediately" id="onbuttontest" name="onbuttontest" onclick="return onbuttontest();">Send Immediately</button>
    Just change that to another submit button and remove the return statement.

    It's inadvisable for an element's ID to clash with the name of any global object.
    Tab-indentation is a crime against humanity.


Bookmarks

Posting Permissions

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